From f817f108585bf9443b9893c9d4723091abbc9a98 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Tue, 29 Mar 2016 11:49:29 -0400 Subject: [PATCH] Module code: syntax validation Assert that module code is parsed as specified. --- .../parse-err-export-dflt-const.js | 11 ++++++ .../module-code/parse-err-export-dflt-expr.js | 21 ++++++++++ .../module-code/parse-err-export-dflt-let.js | 11 ++++++ .../module-code/parse-err-export-dflt-var.js | 11 ++++++ .../module-code/parse-err-hoist-lex-fun.js | 21 ++++++++++ .../module-code/parse-err-hoist-lex-gen.js | 22 +++++++++++ .../parse-err-invoke-anon-fun-decl.js | 21 ++++++++++ .../parse-err-invoke-anon-gen-decl.js | 22 +++++++++++ .../module-code/parse-err-reference.js | 18 +++++++++ .../module-code/parse-err-semi-dflt-expr.js | 22 +++++++++++ .../parse-err-semi-export-clause-from.js | 22 +++++++++++ .../parse-err-semi-export-clause.js | 22 +++++++++++ .../module-code/parse-err-semi-export-star.js | 21 ++++++++++ test/language/module-code/parse-err-syntax.js | 18 +++++++++ .../module-code/parse-export-empty.js | 38 +++++++++++++++++++ 15 files changed, 301 insertions(+) create mode 100644 test/language/module-code/parse-err-export-dflt-const.js create mode 100644 test/language/module-code/parse-err-export-dflt-expr.js create mode 100644 test/language/module-code/parse-err-export-dflt-let.js create mode 100644 test/language/module-code/parse-err-export-dflt-var.js create mode 100644 test/language/module-code/parse-err-hoist-lex-fun.js create mode 100644 test/language/module-code/parse-err-hoist-lex-gen.js create mode 100644 test/language/module-code/parse-err-invoke-anon-fun-decl.js create mode 100644 test/language/module-code/parse-err-invoke-anon-gen-decl.js create mode 100644 test/language/module-code/parse-err-reference.js create mode 100644 test/language/module-code/parse-err-semi-dflt-expr.js create mode 100644 test/language/module-code/parse-err-semi-export-clause-from.js create mode 100644 test/language/module-code/parse-err-semi-export-clause.js create mode 100644 test/language/module-code/parse-err-semi-export-star.js create mode 100644 test/language/module-code/parse-err-syntax.js create mode 100644 test/language/module-code/parse-export-empty.js diff --git a/test/language/module-code/parse-err-export-dflt-const.js b/test/language/module-code/parse-err-export-dflt-const.js new file mode 100644 index 0000000000..ca886476e1 --- /dev/null +++ b/test/language/module-code/parse-err-export-dflt-const.js @@ -0,0 +1,11 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-exports +es6id: 15.2.3 +description: The default export may not be a LexicalDeclaration (const) +flags: [module] +negative: SyntaxError +---*/ + +export default const x = null; diff --git a/test/language/module-code/parse-err-export-dflt-expr.js b/test/language/module-code/parse-err-export-dflt-expr.js new file mode 100644 index 0000000000..61c05e4913 --- /dev/null +++ b/test/language/module-code/parse-err-export-dflt-expr.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Expression not permitted in AssignmentExpression position +esid: sec-exports +info: | + ExportDeclaration: + export * FromClause; + export ExportClause FromClause; + export ExportClause; + export VariableStatement + export Declaration + export default HoistableDeclaration[Default] + export default ClassDeclaration[Default] + export default [lookahead ∉ { function, class }] AssignmentExpression[In]; +negative: SyntaxError +flags: [module] +---*/ + +export default null, null; diff --git a/test/language/module-code/parse-err-export-dflt-let.js b/test/language/module-code/parse-err-export-dflt-let.js new file mode 100644 index 0000000000..cb3ae054b0 --- /dev/null +++ b/test/language/module-code/parse-err-export-dflt-let.js @@ -0,0 +1,11 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-exports +es6id: 15.2.3 +description: The default export may not be a LexicalDeclaration (let) +flags: [module] +negative: SyntaxError +---*/ + +export default let x; diff --git a/test/language/module-code/parse-err-export-dflt-var.js b/test/language/module-code/parse-err-export-dflt-var.js new file mode 100644 index 0000000000..5cd5102168 --- /dev/null +++ b/test/language/module-code/parse-err-export-dflt-var.js @@ -0,0 +1,11 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-exports +es6id: 15.2.3 +description: The default export may not be a VariableStatement +flags: [module] +negative: SyntaxError +---*/ + +export default var x; diff --git a/test/language/module-code/parse-err-hoist-lex-fun.js b/test/language/module-code/parse-err-hoist-lex-fun.js new file mode 100644 index 0000000000..98c95ae674 --- /dev/null +++ b/test/language/module-code/parse-err-hoist-lex-fun.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Function declarations are interpreted as lexically-scoped in module code +esid: sec-module-semantics-static-semantics-lexicallydeclarednames +info: | + ModuleItem : StatementListItem + + 1. Return LexicallyDeclaredNames of StatementListItem. + + 15.2.1.1 Static Semantics: Early Errors + + - It is a Syntax Error if any element of the LexicallyDeclaredNames of + ModuleItemList also occurs in the VarDeclaredNames of ModuleItemList. +negative: SyntaxError +flags: [module] +---*/ + +var f; +function f() {} diff --git a/test/language/module-code/parse-err-hoist-lex-gen.js b/test/language/module-code/parse-err-hoist-lex-gen.js new file mode 100644 index 0000000000..6f32a70240 --- /dev/null +++ b/test/language/module-code/parse-err-hoist-lex-gen.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Generator function declarations are interpreted as lexically-scoped in + module code +esid: sec-module-semantics-static-semantics-lexicallydeclarednames +info: | + ModuleItem : StatementListItem + + 1. Return LexicallyDeclaredNames of StatementListItem. + + 15.2.1.1 Static Semantics: Early Errors + + - It is a Syntax Error if any element of the LexicallyDeclaredNames of + ModuleItemList also occurs in the VarDeclaredNames of ModuleItemList. +negative: SyntaxError +flags: [module] +---*/ + +var g; +function* g() {} diff --git a/test/language/module-code/parse-err-invoke-anon-fun-decl.js b/test/language/module-code/parse-err-invoke-anon-fun-decl.js new file mode 100644 index 0000000000..e161036907 --- /dev/null +++ b/test/language/module-code/parse-err-invoke-anon-fun-decl.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Anonymous function declaration must not be interpreted as an expression +esid: sec-exports +info: | + ExportDeclaration: + export * FromClause; + export ExportClause FromClause; + export ExportClause; + export VariableStatement + export Declaration + export default HoistableDeclaration[Default] + export default ClassDeclaration[Default] + export default [lookahead ∉ { function, class }] AssignmentExpression[In]; +negative: SyntaxError +flags: [module] +---*/ + +export default function() {}(); diff --git a/test/language/module-code/parse-err-invoke-anon-gen-decl.js b/test/language/module-code/parse-err-invoke-anon-gen-decl.js new file mode 100644 index 0000000000..68c13642fe --- /dev/null +++ b/test/language/module-code/parse-err-invoke-anon-gen-decl.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Anonymous generator function declaration must not be interpreted as an + expression +esid: sec-exports +info: | + ExportDeclaration: + export * FromClause; + export ExportClause FromClause; + export ExportClause; + export VariableStatement + export Declaration + export default HoistableDeclaration[Default] + export default ClassDeclaration[Default] + export default [lookahead ∉ { function, class }] AssignmentExpression[In]; +negative: SyntaxError +flags: [module] +---*/ + +export default function* () {}(); diff --git a/test/language/module-code/parse-err-reference.js b/test/language/module-code/parse-err-reference.js new file mode 100644 index 0000000000..8521599c0e --- /dev/null +++ b/test/language/module-code/parse-err-reference.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Early ReferenceError resulting from module parsing +esid: sec-parsemodule +negative: ReferenceError +info: | + [...] + 2. Parse sourceText using Module as the goal symbol and analyze the parse + result for any Early Error conditions. If the parse was successful and + no early errors were found, let body be the resulting parse tree. + Otherwise, let body be a List of one or more SyntaxError or + ReferenceError objects representing the parsing errors and/or early + errors. +flags: [module] +---*/ + +1++; diff --git a/test/language/module-code/parse-err-semi-dflt-expr.js b/test/language/module-code/parse-err-semi-dflt-expr.js new file mode 100644 index 0000000000..78cba692fd --- /dev/null +++ b/test/language/module-code/parse-err-semi-dflt-expr.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + "export default AssignmentExpression" declarations require a trailing + semicolon or LineTerminator +esid: sec-exports +info: | + ExportDeclaration: + export * FromClause; + export ExportClause FromClause; + export ExportClause; + export VariableStatement + export Declaration + export default HoistableDeclaration[Default] + export default ClassDeclaration[Default] + export default [lookahead ∉ { function, class }] AssignmentExpression[In]; +negative: SyntaxError +flags: [module] +---*/ + +export default null null; diff --git a/test/language/module-code/parse-err-semi-export-clause-from.js b/test/language/module-code/parse-err-semi-export-clause-from.js new file mode 100644 index 0000000000..b581cd3e65 --- /dev/null +++ b/test/language/module-code/parse-err-semi-export-clause-from.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + "export ExportClause FromClause" declarations require a trailing semicolon + or LineTerminator +esid: sec-exports +info: | + ExportDeclaration: + export * FromClause; + export ExportClause FromClause; + export ExportClause; + export VariableStatement + export Declaration + export default HoistableDeclaration[Default] + export default ClassDeclaration[Default] + export default [lookahead ∉ { function, class }] AssignmentExpression[In]; +negative: SyntaxError +flags: [module] +---*/ + +export {} from './parse-err-semi-export-clause-from.js' null; diff --git a/test/language/module-code/parse-err-semi-export-clause.js b/test/language/module-code/parse-err-semi-export-clause.js new file mode 100644 index 0000000000..7b45846291 --- /dev/null +++ b/test/language/module-code/parse-err-semi-export-clause.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + "export ExportClause" declarations require a trailing semicolon or + LineTerminator +esid: sec-exports +info: | + ExportDeclaration: + export * FromClause; + export ExportClause FromClause; + export ExportClause; + export VariableStatement + export Declaration + export default HoistableDeclaration[Default] + export default ClassDeclaration[Default] + export default [lookahead ∉ { function, class }] AssignmentExpression[In]; +negative: SyntaxError +flags: [module] +---*/ + +export {} null; diff --git a/test/language/module-code/parse-err-semi-export-star.js b/test/language/module-code/parse-err-semi-export-star.js new file mode 100644 index 0000000000..cc8f908891 --- /dev/null +++ b/test/language/module-code/parse-err-semi-export-star.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + "export *" declarations require a trailing semicolon or LineTerminator +esid: sec-exports +info: | + ExportDeclaration: + export * FromClause; + export ExportClause FromClause; + export ExportClause; + export VariableStatement + export Declaration + export default HoistableDeclaration[Default] + export default ClassDeclaration[Default] + export default [lookahead ∉ { function, class }] AssignmentExpression[In]; +negative: SyntaxError +flags: [module] +---*/ + +export * from './parse-err-semi-export-star.js' null; diff --git a/test/language/module-code/parse-err-syntax.js b/test/language/module-code/parse-err-syntax.js new file mode 100644 index 0000000000..ec36f521c6 --- /dev/null +++ b/test/language/module-code/parse-err-syntax.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Early SyntaxError resulting from module parsing +esid: sec-parsemodule +negative: SyntaxError +info: | + [...] + 2. Parse sourceText using Module as the goal symbol and analyze the parse + result for any Early Error conditions. If the parse was successful and + no early errors were found, let body be the resulting parse tree. + Otherwise, let body be a List of one or more SyntaxError or + ReferenceError objects representing the parsing errors and/or early + errors. +flags: [module] +---*/ + +? diff --git a/test/language/module-code/parse-export-empty.js b/test/language/module-code/parse-export-empty.js new file mode 100644 index 0000000000..fd95dcc3a7 --- /dev/null +++ b/test/language/module-code/parse-export-empty.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: An ExportClause does not require an ExportsList. +esid: sec-parsemodule +info: | + ExportDeclaration: + export * FromClause; + export ExportClause FromClause; + export ExportClause; + export VariableStatement + export Declaration + export default HoistableDeclaration[Default] + export default ClassDeclaration[Default] + export default [lookahead ∉ { function, class }] AssignmentExpression[In]; + + ExportClause: + { } + { ExportsList } + { ExportsList , } + + NOTE: This form has no observable side effects. +flags: [module] +---*/ + +export{}; +export {}; +export {} +export { }; +export +{ + +}; +export//- +{//- +//- +}; +export/**/{/**/};