Rework module parsing and execution (#4462)

This patch disables automatic detection of module code, and instead
requires the user to explicitly specify whether to parse a source
as a module or as a script.

To achieve this the jerry_parse API function now takes a new option
which signals that the source should be parsed as a module.

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu
This commit is contained in:
Dániel Bátyai
2021-01-18 15:33:43 +01:00
committed by GitHub
parent ef8a6a9f39
commit 0fec9135ec
85 changed files with 575 additions and 492 deletions
@@ -13,8 +13,8 @@
* limitations under the License.
*/
export {} from "module-export-01.js";
export {aa,} from "module-export-01.js";
export {bb as b_, cc as c_} from "module-export-01.js";
export * from "module-export-01.js";
export {} from "module-export-01.mjs";
export {aa,} from "module-export-01.mjs";
export {bb as b_, cc as c_} from "module-export-01.mjs";
export * from "module-export-01.mjs";
export default function () {return "default"};
@@ -23,4 +23,4 @@ export default class {
}
}
export * from "module-export-02.js"
export * from "module-export-02.mjs"
@@ -13,6 +13,6 @@
* limitations under the License.
*/
export * from "module-export-01.js";
export * from "module-export-04.js";
export * from "module-export-01.mjs";
export * from "module-export-04.mjs";
export default a = "str"
@@ -14,6 +14,6 @@
*/
export {}
export {} from "module-export-01.js";
export {} from "module-export-01.mjs";
export {};
export {} from "module-export-04.js"
export {} from "module-export-04.mjs"
@@ -13,5 +13,5 @@
* limitations under the License.
*/
export * from "./module-export-04.js";
export * from "./module-export-04.mjs";
export let c = 5;
@@ -13,13 +13,13 @@
* limitations under the License.
*/
import "./module-export-01.js";
import def from "module-export-01.js";
import {} from "module-export-01.js";
import {aa as a,} from "module-export-01.js";
import {bb as b, cc as c} from "module-export-01.js";
import {x} from "module-export-01.js";
import * as mod from "module-export-01.js";
import "./module-export-01.mjs";
import def from "module-export-01.mjs";
import {} from "module-export-01.mjs";
import {aa as a,} from "module-export-01.mjs";
import {bb as b, cc as c} from "module-export-01.mjs";
import {x} from "module-export-01.mjs";
import * as mod from "module-export-01.mjs";
assert (def === "default");
assert (a === "a");
@@ -13,8 +13,8 @@
* limitations under the License.
*/
import def, * as mod from "module-export-02.js";
import {b_, c_,} from "module-export-02.js";
import def, * as mod from "module-export-02.mjs";
import {b_, c_,} from "module-export-02.mjs";
assert (def() === "default")
assert (mod.aa === "a")
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import incrementer, {aa, c_, x,} from "module-export-03.js"
import incrementer, {aa, c_, x,} from "module-export-03.mjs"
var i = new incrementer(3);
assert(i.incr() === 4);
assert(i.incr() === 5);
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import "module-import-01.js";
import "module-export-05.js";
import "module-export-06.js";
import "module-export-07.js";
import "module-import-01.mjs";
import "module-export-05.mjs";
import "module-export-06.mjs";
import "module-export-07.mjs";
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import * as f from "./module-export-08.js";
import * as f from "./module-export-08.mjs";
assert (f.c === 5)
assert (f.x === 41)
@@ -22,6 +22,6 @@ getNamePromise(collector).then(() => { collector["end"] = resourceName(); });
function __checkAsync() {
assert(collector["start"].endsWith("module-resource-name-export.mjs"));
assert(collector["middle"].endsWith("module-resource-name-export.mjs"));
assert(collector["end"].endsWith("module-resource-name.js"));
assert(collector["end"].endsWith("module-resource-name.mjs"));
assert(Object.keys(collector).length === 3);
}
@@ -16,7 +16,7 @@
/* Import/export statements must be in the global scope. */
var eval = eval.bind();
try {
eval('import { c } from "tests/jerry/es.next/module-export-01.js";');
eval('import { c } from "tests/jerry/es.next/module-export-01.mjs";');
assert (false);
} catch (e) {
assert (e instanceof SyntaxError);
@@ -14,4 +14,4 @@
*/
// File does not exist.
import b from "module-exports.js"
import b from "module-exports.mjs"
@@ -13,4 +13,4 @@
* limitations under the License.
*/
import { , as b } from "../es.next/module-export-01.js";
import { , as b } from "../es.next/module-export-01.mjs";
@@ -13,4 +13,4 @@
* limitations under the License.
*/
import , as b from "../es.next/module-export-01.js";
import , as b from "../es.next/module-export-01.mjs";
-16
View File
@@ -1,16 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { b as , } from "../es.next/module-export-01.js";
+16
View File
@@ -0,0 +1,16 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { b as , } from "../es.next/module-export-01.mjs";
@@ -14,4 +14,4 @@
*/
/* Named imports must be in a NamedImports block. */
import b as , from "../es.next/module-export-01.js";
import b as , from "../es.next/module-export-01.mjs";
@@ -14,4 +14,4 @@
*/
/* Module requests must always be evaluated. */
import "./module-sideeffect.js"
import "./module-sideeffect.mjs"
@@ -14,4 +14,4 @@
*/
/* Can't have duplicate local bindings */
import { c as a, d as a } from "../es.next/module-export-01.js";
import { c as a, d as a } from "../es.next/module-export-01.mjs";
@@ -15,5 +15,5 @@
/* Import/export statements must be in the global scope. */
if (true) {
import { c } from "../es.next/module-export-01.js";
import { c } from "../es.next/module-export-01.mjs";
}
@@ -15,5 +15,5 @@
/* Import/export statements must be in the global scope. */
function someFunction() {
import { c } from "../es.next/module-export-01.js";
import { c } from "../es.next/module-export-01.mjs";
}
@@ -14,4 +14,4 @@
*/
/* Import/export statements must be in the global scope. */
eval ('import { c } from "../es.next/module-export-01.js";');
eval ('import { c } from "../es.next/module-export-01.mjs";');
@@ -14,4 +14,4 @@
*/
/* NamedImports must always be followed by a FromClause. */
import { b }, from "../es.next/module-export-01.js"
import { b }, from "../es.next/module-export-01.mjs"
@@ -14,4 +14,4 @@
*/
/* An import statement can have either a NameSpaceImport or NamedIpmorts */
import * as mod, { b } from "../es.next/module-export-01.js"
import * as mod, { b } from "../es.next/module-export-01.mjs"
@@ -14,4 +14,4 @@
*/
/* '*' is not valid inside NamedImports. */
import { *, d } from "../es.next/module-imported-01.js"
import { *, d } from "../es.next/module-imported-01.mjs"
@@ -14,5 +14,5 @@
*/
/* Can't have duplicated local bindings. */
import { b } from "../es.next/module-export-01.js"
import { b } from "../es.next/module-export-02.js"
import { b } from "../es.next/module-export-01.mjs"
import { b } from "../es.next/module-export-02.mjs"
@@ -14,4 +14,4 @@
*/
/* FromClause must follow an ImportClause. */
import from "../es.next/module-export-02.js"
import from "../es.next/module-export-02.mjs"
@@ -14,4 +14,4 @@
*/
/* Namespace imports must have a local name. */
import * from "../es.next/module-export-01.js"
import * from "../es.next/module-export-01.mjs"
@@ -14,4 +14,4 @@
*/
/* Star exports can't have an export name. */
export * as star from "../es.next/module-export-01.js"
export * as star from "../es.next/module-export-01.mjs"
@@ -14,4 +14,4 @@
*/
/* Indirect exports must be checked if they are resolvable. */
export { l } from "../es.next/module-export-01.js"
export { l } from "../es.next/module-export-01.mjs"
@@ -14,4 +14,4 @@
*/
/* Can't have circular imports/exports. */
export { b } from "./module-027.js"
export { b } from "./module-027.mjs"
@@ -14,4 +14,4 @@
*/
/* Can't have circular imports/exports. */
export { b } from "./module-026.js"
export { b } from "./module-026.mjs"
@@ -14,4 +14,4 @@
*/
/* Ambiguous import */
import { x } from "../es.next/module-export-05.js"
import { x } from "../es.next/module-export-05.mjs"
@@ -14,4 +14,4 @@
*/
/* Import/export statements must be in the global scope. */
Function('','import { c } from "../es.next/module-export-01.js";')
Function('','import { c } from "../es.next/module-export-01.mjs";')
@@ -14,4 +14,4 @@
*/
/* No default export found. */
import def from "../es.next/module-export-06.js"
import def from "../es.next/module-export-06.mjs"
@@ -14,4 +14,4 @@
*/
let a;
import { a } from "../es.next/module-export-fail-test.js";
import { a } from "../es.next/module-export-fail-test.mjs";
@@ -14,4 +14,4 @@
*/
var a;
import { a } from "../es.next/module-export-fail-test.js";
import { a } from "../es.next/module-export-fail-test.mjs";
@@ -13,5 +13,5 @@
* limitations under the License.
*/
import { a } from "../es.next/module-export-fail-test.js";
import { a } from "../es.next/module-export-fail-test.mjs";
class a {};
@@ -13,5 +13,5 @@
* limitations under the License.
*/
import { a } from "../es.next/module-export-fail-test.js";
import { a } from "../es.next/module-export-fail-test.mjs";
function a() {}
@@ -13,4 +13,4 @@
* limitations under the License.
*/
import "./module-export-001.js"
import "./module-await-001.mjs"
@@ -13,4 +13,4 @@
* limitations under the License.
*/
import "./module-await-001.js"
import "./module-await-001.mjs"
@@ -12,5 +12,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.
export {} from "dummy.js";
export {} from "../es.next/module-export-04.js";
export {} from "dummy.mjs";
export {} from "../es.next/module-export-04.mjs";
-19
View File
@@ -328,8 +328,6 @@
<test id="language/expressions/call/eval-spread.js"><reason></reason></test>
<test id="language/expressions/class/accessor-name-inst/literal-numeric-leading-decimal.js"><reason></reason></test>
<test id="language/expressions/class/accessor-name-static/literal-numeric-leading-decimal.js"><reason></reason></test>
<test id="language/expressions/class/class-name-ident-await-escaped-module.js"><reason></reason></test>
<test id="language/expressions/class/class-name-ident-await-module.js"><reason></reason></test>
<test id="language/expressions/class/class-name-ident-let-escaped.js"><reason></reason></test>
<test id="language/expressions/class/class-name-ident-let.js"><reason></reason></test>
<test id="language/expressions/class/class-name-ident-static-escaped.js"><reason></reason></test>
@@ -414,7 +412,6 @@
<test id="language/expressions/yield/star-return-is-null.js"><reason></reason></test>
<test id="language/expressions/yield/star-throw-is-null.js"><reason></reason></test>
<test id="language/global-code/decl-lex-configurable-global.js"><reason></reason></test>
<test id="language/global-code/export.js"><reason></reason></test>
<test id="language/identifiers/part-unicode-10.0.0-escaped.js"><reason></reason></test>
<test id="language/identifiers/part-unicode-10.0.0.js"><reason></reason></test>
<test id="language/identifiers/part-unicode-11.0.0-escaped.js"><reason></reason></test>
@@ -457,7 +454,6 @@
<test id="language/identifiers/start-unicode-9.0.0.js"><reason></reason></test>
<test id="language/literals/regexp/unicode-escape-nls-err.js"><reason></reason></test>
<test id="language/literals/string/legacy-octal-escape-sequence-prologue-strict.js"><reason></reason></test>
<test id="language/module-code/early-strict-mode.js"><reason></reason></test>
<test id="language/module-code/eval-export-cls-semi.js"><reason></reason></test>
<test id="language/module-code/eval-export-dflt-cls-anon-semi.js"><reason></reason></test>
<test id="language/module-code/eval-export-dflt-cls-anon.js"><reason></reason></test>
@@ -487,7 +483,6 @@
<test id="language/module-code/eval-rqstd-once.js"><reason></reason></test>
<test id="language/module-code/eval-rqstd-order.js"><reason></reason></test>
<test id="language/module-code/eval-self-once.js"><reason></reason></test>
<test id="language/module-code/eval-this.js"><reason></reason></test>
<test id="language/module-code/export-star-as-dflt.js"><reason></reason></test>
<test id="language/module-code/instn-iee-bndng-cls.js"><reason></reason></test>
<test id="language/module-code/instn-iee-bndng-const.js"><reason></reason></test>
@@ -498,13 +493,6 @@
<test id="language/module-code/instn-iee-iee-cycle.js"><reason></reason></test>
<test id="language/module-code/instn-iee-star-cycle.js"><reason></reason></test>
<test id="language/module-code/instn-iee-trlng-comma.js"><reason></reason></test>
<test id="language/module-code/instn-local-bndng-export-fun.js"><reason></reason></test>
<test id="language/module-code/instn-local-bndng-export-gen.js"><reason></reason></test>
<test id="language/module-code/instn-local-bndng-export-var.js"><reason></reason></test>
<test id="language/module-code/instn-local-bndng-for.js"><reason></reason></test>
<test id="language/module-code/instn-local-bndng-fun.js"><reason></reason></test>
<test id="language/module-code/instn-local-bndng-gen.js"><reason></reason></test>
<test id="language/module-code/instn-local-bndng-var.js"><reason></reason></test>
<test id="language/module-code/instn-named-bndng-cls.js"><reason></reason></test>
<test id="language/module-code/instn-named-bndng-const.js"><reason></reason></test>
<test id="language/module-code/instn-named-bndng-dflt-cls.js"><reason></reason></test>
@@ -576,13 +564,9 @@
<test id="language/module-code/namespace/internals/set.js"><reason></reason></test>
<test id="language/module-code/parse-err-hoist-lex-fun.js"><reason></reason></test>
<test id="language/module-code/parse-err-hoist-lex-gen.js"><reason></reason></test>
<test id="language/module-code/parse-err-yield.js"><reason></reason></test>
<test id="language/reserved-words/await-module.js"><reason></reason></test>
<test id="language/statements/async-function/let-newline-await-in-async-function.js"><reason></reason></test>
<test id="language/statements/class/accessor-name-inst/literal-numeric-leading-decimal.js"><reason></reason></test>
<test id="language/statements/class/accessor-name-static/literal-numeric-leading-decimal.js"><reason></reason></test>
<test id="language/statements/class/class-name-ident-await-escaped-module.js"><reason></reason></test>
<test id="language/statements/class/class-name-ident-await-module.js"><reason></reason></test>
<test id="language/statements/class/class-name-ident-let-escaped.js"><reason></reason></test>
<test id="language/statements/class/class-name-ident-let.js"><reason></reason></test>
<test id="language/statements/class/class-name-ident-static-escaped.js"><reason></reason></test>
@@ -699,8 +683,6 @@
<test id="language/statements/labeled/decl-gen.js"><reason></reason></test>
<test id="language/statements/labeled/let-block-with-newline.js"><reason></reason></test>
<test id="language/statements/labeled/let-identifier-with-newline.js"><reason></reason></test>
<test id="language/statements/labeled/value-await-module-escaped.js"><reason></reason></test>
<test id="language/statements/labeled/value-await-module.js"><reason></reason></test>
<test id="language/statements/let/dstr/ary-init-iter-no-close.js"><reason></reason></test>
<test id="language/statements/let/syntax/let-newline-yield-in-generator-function.js"><reason></reason></test>
<test id="language/statements/switch/cptn-a-abrupt-empty.js"><reason></reason></test>
@@ -5242,7 +5224,6 @@
<test id="language/module-code/top-level-await/module-import-unwrapped.js"><reason></reason></test>
<test id="language/module-code/top-level-await/module-self-import-async-resolution-ticks.js"><reason></reason></test>
<test id="language/module-code/top-level-await/module-sync-import-async-resolution-ticks.js"><reason></reason></test>
<test id="language/module-code/top-level-await/no-operand.js"><reason></reason></test>
<test id="language/module-code/top-level-await/syntax/await-expr-dyn-import.js"><reason></reason></test>
<test id="language/module-code/top-level-await/syntax/block-await-expr-array-literal.js"><reason></reason></test>
<test id="language/module-code/top-level-await/syntax/block-await-expr-func-expression.js"><reason></reason></test>