diff options
Diffstat (limited to 'js/src/jit-test/tests/modules/import-meta-expression.js')
-rw-r--r-- | js/src/jit-test/tests/modules/import-meta-expression.js | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/modules/import-meta-expression.js b/js/src/jit-test/tests/modules/import-meta-expression.js new file mode 100644 index 0000000000..e7562afaed --- /dev/null +++ b/js/src/jit-test/tests/modules/import-meta-expression.js @@ -0,0 +1,91 @@ +load(libdir + "match.js"); +load(libdir + "asserts.js"); + +var { Pattern, MatchError } = Match; + +program = (elts) => Pattern({ + type: "Program", + body: elts +}); +expressionStatement = (expression) => Pattern({ + type: "ExpressionStatement", + expression: expression +}); +assignmentExpression = (left, operator, right) => Pattern({ + type: "AssignmentExpression", + operator: operator, + left: left, + right: right +}); +ident = (name) => Pattern({ + type: "Identifier", + name: name +}); +metaProperty = (meta, property) => Pattern({ + type: "MetaProperty", + meta: meta, + property: property +}); +memberExpression = (object, property) => Pattern({ + type: "MemberExpression", + object: object, + property: property +}); + +function parseAsModule(source) +{ + return Reflect.parse(source, {target: "module"}); +} + +program([ + expressionStatement( + metaProperty( + ident("import"), + ident("meta") + ) + ) +]).assert(parseAsModule("import.meta;")); + +program([ + expressionStatement( + assignmentExpression( + ident("x"), + "=", + metaProperty( + ident("import"), + ident("meta") + ) + ) + ) +]).assert(parseAsModule("x = import.meta;")); + +program([ + expressionStatement( + assignmentExpression( + memberExpression( + metaProperty( + ident("import"), + ident("meta") + ), + ident("foo") + ), + "=", + ident("x"), + ) + ) +]).assert(parseAsModule("import.meta.foo = x;")); + +function assertModuleParseThrowsSyntaxError(source) +{ + assertThrowsInstanceOf(() => parseAsModule(source), SyntaxError); +} + +assertModuleParseThrowsSyntaxError("import"); +assertModuleParseThrowsSyntaxError("import."); +assertModuleParseThrowsSyntaxError("import.met"); +assertModuleParseThrowsSyntaxError("import.metaa"); +assertModuleParseThrowsSyntaxError("x = import"); +assertModuleParseThrowsSyntaxError("x = import."); +assertModuleParseThrowsSyntaxError("x = import.met"); +assertModuleParseThrowsSyntaxError("x = import.metaa"); +assertModuleParseThrowsSyntaxError("import.meta = x"); |