Rework ES2015 module system and add missing features. (#2792)

Co-authored-by: Dániel Bátyai <dbatyai@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Daniel Vince vinced@inf.u-szeged.hu
This commit is contained in:
Daniel Vince
2019-04-25 14:57:17 +02:00
committed by Robert Fancsik
parent 938e9c7530
commit 37b7645e6a
59 changed files with 2209 additions and 991 deletions
+41
View File
@@ -0,0 +1,41 @@
/* 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 {};
export {a as aa,};
export {b as bb, c as cc};
export {d};
export var x = 42;
export function f(a) {return a;};
export class Dog {
constructor (name) {
this.name = name;
}
speak() {
return this.name + " barks."
}
};
export default "default";
var a = "a";
var b = 5;
var c = function(a) { return 2 * a;}
var d = [1,2,3];
assert (x === 42);
assert (f(1) === 1);
var dog = new Dog("Pluto")
assert(dog.speak() === "Pluto barks.")
+20
View File
@@ -0,0 +1,20 @@
/* 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 {} from "tests/jerry/es2015/module-export-01.js";
export {aa,} from "tests/jerry/es2015/module-export-01.js";
export {bb as b_, cc as c_} from "tests/jerry/es2015/module-export-01.js";
export * from "tests/jerry/es2015/module-export-01.js";
export default function () {return "default"};
@@ -13,19 +13,14 @@
* limitations under the License.
*/
export function getString (prefix) {
return prefix + "String";
export default class {
constructor(num) {
this.num = num
}
incr() {
return ++(this.num);
}
}
function getAreaOfCircle (radius) {
return radius * radius * pi;
}
export getAreaOfCircle as getArea;
import { pi } from "tests/jerry/es2015/module-imported-3.js";
assert (pi === 3.14);
export pi as b;
assert (true);
export * from "tests/jerry/es2015/module-export-02.js"
@@ -13,19 +13,5 @@
* limitations under the License.
*/
var a = 1;
function b () {
return 2;
}
export var c = 3;
export function d () {
return 4;
}
export { a as e, b }
export var f = "str";
assert (true);
export var x = 41
export default a = "str"
+18
View File
@@ -0,0 +1,18 @@
/* 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 * from "tests/jerry/es2015/module-export-01.js";
export * from "tests/jerry/es2015/module-export-04.js";
export default a = "str"
+19
View File
@@ -0,0 +1,19 @@
/* 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 {}
export {} from "tests/jerry/es2015/module-export-01.js";
export {};
export {} from "tests/jerry/es2015/module-export-04.js"
@@ -13,6 +13,4 @@
* limitations under the License.
*/
export var pi = 3.14;
assert (true);
export default x = y = z = "default";
+33
View File
@@ -0,0 +1,33 @@
/* 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 "tests/jerry/es2015/module-export-01.js";
import def from "tests/jerry/es2015/module-export-01.js";
import {} from "tests/jerry/es2015/module-export-01.js";
import {aa as a,} from "tests/jerry/es2015/module-export-01.js";
import {bb as b, cc as c} from "tests/jerry/es2015/module-export-01.js";
import {x} from "tests/jerry/es2015/module-export-01.js";
import * as mod from "tests/jerry/es2015/module-export-01.js";
assert (def === "default");
assert (a === "a");
assert (b === 5);
assert (c(b) === 10);
assert (Array.isArray(mod.d))
assert (x === 42)
assert (mod.f("str") === "str")
dog = new mod.Dog("Oddie")
assert (dog.speak() === "Oddie barks.")
@@ -13,23 +13,12 @@
* limitations under the License.
*/
import { b, c, d, e, f as g } from "tests/jerry/es2015/module-imported.js"
import def, * as mod from "tests/jerry/es2015/module-export-02.js";
import {b_, c_,} from "tests/jerry/es2015/module-export-02.js";
import
{
b as pi,
getString,
getArea
} from "tests/jerry/es2015/module-imported-2.js"
var str = "str";
assert (b () === 2);
assert (c === 3);
assert (d () === 4);
assert (e === 1);
assert (g === str);
assert (pi === 3.14);
assert (getArea (2) == 12.56);
assert (getString (str) === "strString")
assert (def() === "default")
assert (mod.aa === "a")
assert (b_ === 5)
assert (c_(b_) === 10)
assert (mod.x === 42)
assert (Array.isArray(mod.d))
+24
View File
@@ -0,0 +1,24 @@
/* 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 incrementer, {aa, c_, x,} from "tests/jerry/es2015/module-export-03.js"
var i = new incrementer(3);
assert(i.incr() === 4);
assert(i.incr() === 5);
assert(i.incr() === 6);
assert (aa === "a");
assert (x === 42);
assert (c_(x) == 84);
+1 -1
View File
@@ -13,4 +13,4 @@
* limitations under the License.
*/
import { , as b } from "tests/jerry/es2015/module-imported.js";
import { , as b } from "tests/jerry/es2015/module-export-01.js";
+1 -1
View File
@@ -13,4 +13,4 @@
* limitations under the License.
*/
import , as b from "tests/jerry/es2015/module-imported.js";
import , as b from "tests/jerry/es2015/module-export-01.js";
+1 -1
View File
@@ -13,4 +13,4 @@
* limitations under the License.
*/
import { b as , } from "tests/jerry/es2015/module-imported.js";
import { b as , } from "tests/jerry/es2015/module-export-01.js";
+2 -1
View File
@@ -13,4 +13,5 @@
* limitations under the License.
*/
import b as , from "tests/jerry/es2015/module-imported.js";
/* Named imports must be in a NamedImports block. */
import b as , from "tests/jerry/es2015/module-export-01.js";
+2 -1
View File
@@ -13,4 +13,5 @@
* limitations under the License.
*/
import { as as as } from "tests/jerry/es2015/module-imported.js";
/* Can't have reserved words for the referenced bindings. */
export { yield as y };
+2 -1
View File
@@ -13,4 +13,5 @@
* limitations under the License.
*/
import { from as as } from "tests/jerry/es2015/module-imported.js";
/* Module requests must always be evaluated. */
import "tests/jerry/fail/module-sideeffect.js"
+2 -1
View File
@@ -13,4 +13,5 @@
* limitations under the License.
*/
import { b } from
/* A string literal must always follow the 'from' keyword. */
import { b } from
+1
View File
@@ -13,4 +13,5 @@
* limitations under the License.
*/
/* A string literal must always follow the 'from' keyword. */
import { b } from 3
+2 -1
View File
@@ -13,4 +13,5 @@
* limitations under the License.
*/
import { c as a, d as a } from "tests/jerry/es2015/module-imported.js";
/* Can't have duplicate local bindings */
import { c as a, d as a } from "tests/jerry/es2015/module-export-01.js";
+2 -1
View File
@@ -13,6 +13,7 @@
* limitations under the License.
*/
/* Import/export statements must be in the global scope. */
if (true) {
import { c } from "tests/jerry/es2015/module-imported.js";
import { c } from "tests/jerry/es2015/module-export-01.js";
}
+2 -1
View File
@@ -13,6 +13,7 @@
* limitations under the License.
*/
/* Import/export statements must be in the global scope. */
function someFunction() {
import { c } from "tests/jerry/es2015/module-imported.js";
import { c } from "tests/jerry/es2015/module-export-01.js";
}
+2 -1
View File
@@ -13,4 +13,5 @@
* limitations under the License.
*/
eval ("import { c } from 'tests/jerry/es2015/module-imported.js';");
/* Import/export statements must be in the global scope. */
eval ('import { c } from "tests/jerry/es2015/module-export-01.js";');
+2 -2
View File
@@ -13,5 +13,5 @@
* limitations under the License.
*/
// File does not exist.
import { a } from "tests/jerry/fail/module-exports.js"
/* NamedImports must always be followed by a FromClause. */
import { b }, from "tests/jerry/es2015/module-export-01.js"
+2 -5
View File
@@ -13,8 +13,5 @@
* limitations under the License.
*/
export function getString () {
return prefix;
}
assert (getString());
/* An import statement can have either a NameSpaceImport or NamedIpmorts */
import * as mod, { b } from "tests/jerry/es2015/module-export-01.js"
+1
View File
@@ -13,4 +13,5 @@
* limitations under the License.
*/
/* An ImportClause must be followed by a FromClause. */
import { c }
+17
View File
@@ -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.
*/
/* '*' is not valid inside NamedImports. */
import { *, d } from "tests/jerry/es2015/module-imported-01.js"
+18
View File
@@ -0,0 +1,18 @@
/* 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.
*/
/* Can't have duplicated local bindings. */
import { b } from "tests/jerry/es2015/module-export-01.js"
import { b } from "tests/jerry/es2015/module-export-02.js"
+17
View File
@@ -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.
*/
/* FromClause must follow an ImportClause. */
import from "tests/jerry/es2015/module-export-02.js"
+17
View File
@@ -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.
*/
/* Namespace imports must have a local name. */
import * from "tests/jerry/es2015/module-export-01.js"
+17
View File
@@ -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.
*/
/* Star exports can't have an export name. */
export * as star from "tests/jerry/es2015/module-export-01.js"
+17
View File
@@ -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.
*/
/* Indirect exports must be checked if they are resolvable. */
export { l } from "tests/jerry/es2015/module-export-01.js"
+17
View File
@@ -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.
*/
/* Can't have circular imports/exports. */
export { b } from "tests/jerry/fail/module-027.js"
+17
View File
@@ -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.
*/
/* Can't have circular imports/exports. */
export { b } from "tests/jerry/fail/module-026.js"
+17
View File
@@ -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.
*/
/* Ambiguous import */
import { x } from "tests/jerry/es2015/module-export-05.js"
+17
View File
@@ -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.
*/
/* Import/export statements must be in the global scope. */
Function('','import { c } from "tests/jerry/es2015/module-export-01.js";')
+17
View File
@@ -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.
*/
/* No default export found. */
import def from "tests/jerry/es2015/module-export-06.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.
*/
throw new Error("side-effect")