Skip to content
Snippets Groups Projects
Commit a6dcd0dc authored by Mike Pennisi's avatar Mike Pennisi
Browse files

Add tests for position of module declarations

Assert that ImportDeclaration and ExportDeclaration match only the
ModuleItem symbol.

According to the definition of HostResolveImportedModule, it is
acceptable for an implementation to throw a SyntaxError in the event
that a requested module can neither be found nor created:

> If a Module Record corresponding to the pair referencingModule,
> specifier does not exist or cannot be created, an exception must be
> thrown.

In order to reliably detect a SyntaxError in response to the correct
interpretation of the grammar (and not a SyntaxError from an *incorrect*
interpretation of the grammar followed by a failure to resolve the
requested module), the ModuleSpecifier of ExportDeclarations should
describe a valid resource.
parent 7d345fc9
No related branches found
No related tags found
No related merge requests found
Showing
with 246 additions and 0 deletions
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: The `export` declaration may not appear within eval code
id: sec-scripts
flags: [module]
info: |
Eval code is the source text supplied to the built-in eval function. More
precisely, if the parameter to the built-in eval function is a String, it
is treated as an ECMAScript Script. The eval code for a particular
invocation of eval is the global code portion of that Script.
A.5 Scripts and Modules
Script:
ScriptBodyopt
ScriptBody:
StatementList
---*/
assert.throws(SyntaxError, function() {
eval('export default null;');
});
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: The `import` declaration may not appear within eval code
id: sec-scripts
flags: [module]
info: |
Eval code is the source text supplied to the built-in eval function. More
precisely, if the parameter to the built-in eval function is a String, it
is treated as an ECMAScript Script. The eval code for a particular
invocation of eval is the global code portion of that Script.
A.5 Scripts and Modules
Script:
ScriptBodyopt
ScriptBody:
StatementList
---*/
assert.throws(SyntaxError, function() {
eval('import v from "./import.js";');
});
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: The `export` declaration may not appear within a ScriptBody
id: sec-scripts
negative: SyntaxError
info: |
A.5 Scripts and Modules
Script:
ScriptBodyopt
ScriptBody:
StatementList
---*/
export default null;
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: The `import` declaration may not appear within a ScriptBody
id: sec-scripts
negative: SyntaxError
info: |
A.5 Scripts and Modules
Script:
ScriptBodyopt
ScriptBody:
StatementList
---*/
import v from './import.js';
// 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 cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
() => { export default null; };
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
{ void 0; export default null; }
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
{ export default null; }
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
class C { static method() { export default null; } }
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
class C { method() { export default null; } }
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
class C { static *method() { export default null; } }
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
class C { *method() { export default null; } }
// 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 cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
(class { static *method() { export default null; } });
// 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 cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
(class { *method() { export default null; } });
// 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 cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
(class { static method() { export default null; } });
// 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 cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
(class { method() { export default null; } });
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
do export default null; while (false)
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
for (const x = 0; false;)
export default null;
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
for (const y in [])
export default null;
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
for (let y in [])
export default null;
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement cannot contain an `export` declaration
id: sec-modules
negative: SyntaxError
flags: [module]
---*/
for (y in [])
export default null;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment