Rework export default parsing (#4505)

- Remove SCANNER_LITERAL_POOL_DEFAULT_CLASS_NAME workaround
- Add async and generator function support
- Fix auto semicolon insertion after export statement
- fixes #4150.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2021-01-19 16:30:41 +01:00
committed by GitHub
parent 3e548401fd
commit bf7fa39581
17 changed files with 387 additions and 112 deletions
+3 -3
View File
@@ -17,8 +17,8 @@ export {};
export {a as aa,};
export {b as bb, c as cc};
export {d};
export var x = 42;
export function f(a) {return a;};
export var x = 40;
export function f(a) {return a;} x++; /* test auto semicolon insertion */
export class Dog {
constructor (name) {
this.name = name;
@@ -27,7 +27,7 @@ export class Dog {
speak() {
return this.name + " barks."
}
};
} x++; /* test auto semicolon insertion */
export default "default";
var a = "a";
@@ -0,0 +1,17 @@
// 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.
let counter = 0.1;
export default function* g() { return "foo1"; } counter++; /* test auto semicolon insertion */
export {counter};
@@ -0,0 +1,17 @@
// 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.
let counter = 1.1;
export default async function* g() { return "foo2"; } counter++; /* test auto semicolon insertion */
export {counter};
@@ -0,0 +1,17 @@
// 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.
let counter = 2.1;
export default async function g() { return "foo3"; } counter++; /* test auto semicolon insertion */
export {counter};
@@ -0,0 +1,17 @@
// 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.
var async = "foo4";
export default async;
@@ -0,0 +1,15 @@
// 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.
export default _ => "foo5";
@@ -0,0 +1,15 @@
// 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.
export default async _ => "foo6";
@@ -0,0 +1,15 @@
// 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.
export default async (a, b) => a + b;
@@ -0,0 +1,17 @@
// 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.
let counter = 7.1;
export default class A { static x = "foo8" } counter++; /* test auto semicolon insertion */
export {counter};
@@ -0,0 +1,17 @@
// 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.
let counter = 8.1;
export default class { static x = "foo9" } counter++; /* test auto semicolon insertion */
export {counter};
@@ -0,0 +1,83 @@
// 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 foo1, { counter as bar1 } from "./module-export-default-1.mjs"
import foo2, { counter as bar2 } from "./module-export-default-2.mjs"
import foo3, { counter as bar3 } from "./module-export-default-3.mjs"
import foo4 from "./module-export-default-4.mjs"
import foo5 from "./module-export-default-5.mjs"
import foo6 from "./module-export-default-6.mjs"
import foo7 from "./module-export-default-7.mjs"
import foo8, { counter as bar8 } from "./module-export-default-8.mjs"
import foo9, { counter as bar9 } from "./module-export-default-9.mjs"
let async_queue_expected = ["foo2", "foo3", "foo6", "foo7"];
let async_queue = [];
(function() {
assert(foo1().next().value === "foo1");
assert(bar1 === 1.1);
})();
(async function() {
async_queue.push((await foo2().next()).value);
assert(bar2 === 2.1);
})();
(async function() {
async_queue.push(await foo3());
assert(bar3 === 3.1);
})();
(function() {
assert(foo4 === "foo4");
})();
(function() {
assert(foo5() === "foo5");
})();
(async function() {
async_queue.push(await foo6());
})();
(async function() {
async_queue.push(await foo7("foo", "7"));
})();
(function() {
assert(foo8.x === "foo8");
assert(bar8 === 8.1);
})();
(function() {
assert(foo9.x === "foo9");
assert(bar9 === 9.1);
})();
Array.prototype.assertArrayEqual = function(expected) {
assert(this.length === expected.length);
print(this);
print(expected);
for (var i = 0; i < this.length; i++) {
assert(this[i] === expected[i]);
}
}
let global = new Function('return this;')();
global.__checkAsync = function() {
async_queue.assertArrayEqual(async_queue_expected);
}
@@ -0,0 +1,15 @@
// 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.
export default () => 1, 5;
-9
View File
@@ -389,11 +389,8 @@
<test id="language/identifiers/start-unicode-9.0.0-escaped.js"><reason></reason></test>
<test id="language/identifiers/start-unicode-9.0.0.js"><reason></reason></test>
<test id="language/literals/string/legacy-octal-escape-sequence-prologue-strict.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>
<test id="language/module-code/eval-export-dflt-cls-name-meth.js"><reason></reason></test>
<test id="language/module-code/eval-export-dflt-cls-named-semi.js"><reason></reason></test>
<test id="language/module-code/eval-export-dflt-cls-named.js"><reason></reason></test>
<test id="language/module-code/eval-export-dflt-expr-cls-anon.js"><reason></reason></test>
<test id="language/module-code/eval-export-dflt-expr-cls-name-meth.js"><reason></reason></test>
@@ -404,12 +401,6 @@
<test id="language/module-code/eval-export-dflt-expr-gen-anon.js"><reason></reason></test>
<test id="language/module-code/eval-export-dflt-expr-gen-named.js"><reason></reason></test>
<test id="language/module-code/eval-export-dflt-expr-in.js"><reason></reason></test>
<test id="language/module-code/eval-export-dflt-fun-anon-semi.js"><reason></reason></test>
<test id="language/module-code/eval-export-dflt-fun-named-semi.js"><reason></reason></test>
<test id="language/module-code/eval-export-dflt-gen-anon-semi.js"><reason></reason></test>
<test id="language/module-code/eval-export-dflt-gen-named-semi.js"><reason></reason></test>
<test id="language/module-code/eval-export-fun-semi.js"><reason></reason></test>
<test id="language/module-code/eval-export-gen-semi.js"><reason></reason></test>
<test id="language/module-code/eval-gtbndng-indirect-trlng-comma.js"><reason></reason></test>
<test id="language/module-code/eval-gtbndng-indirect-update-as.js"><reason></reason></test>
<test id="language/module-code/eval-gtbndng-indirect-update-dflt.js"><reason></reason></test>