Skip to content

Commit

Permalink
feat(parser): 'export' '*' 'as' IdentifierName 'from' ModuleSpecifier…
Browse files Browse the repository at this point in the history
… ';'

tc39/ecma262#1174

@GuyLewin Can you verify if I did this correct?
  • Loading branch information
KFlash committed Nov 5, 2019
1 parent 491271e commit 01db03c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 162 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"**/build": true,
"**/.vscode": true
},
"prettier.singleQuote": true
"prettier.singleQuote": true,
"deepscan.ignoreConfirmWarning": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meriyah",
"version": "1.8.6",
"version": "1.8.7",
"description": "A 100% compliant, self-hosted javascript parser with high focus on both performance and stability",
"main": "dist/meriyah.umd.js",
"module": "dist/meriyah.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion src/meriyah.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ export function parse(source: string, options?: Options): ESTree.Program {
export { Options, ESTree };

// Current version
export const version = '1.8.6';
export const version = '1.8.7';
31 changes: 7 additions & 24 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2876,15 +2876,10 @@ function parseExportDeclaration(
//
// See: https://github.com/tc39/ecma262/pull/1174

let ecma262PR: 0 | 1 = 0;

nextToken(parser, context); // Skips: '*'

if (context & Context.OptionsNext && consumeOpt(parser, context, Token.AsKeyword)) {
ecma262PR = 1;
if (scope) {
declareUnboundVariable(parser, parser.tokenValue);
}
if (consumeOpt(parser, context, Token.AsKeyword)) {
if (scope) declareUnboundVariable(parser, parser.tokenValue);
specifiers.push(
finishNode(parser, context, parser.tokenPos, parser.linePos, parser.colPos, {
type: 'ExportNamespaceSpecifier',
Expand All @@ -2901,23 +2896,11 @@ function parseExportDeclaration(

matchOrInsertSemicolon(parser, context | Context.AllowRegExp);

return finishNode(
parser,
context,
start,
line,
column,
ecma262PR
? {
type: 'ExportNamedDeclaration',
source,
specifiers
}
: ({
type: 'ExportAllDeclaration',
source
} as any)
);
return finishNode(parser, context, start, line, column, {
type: 'ExportNamedDeclaration',
source,
specifiers
} as any);
}
case Token.LeftBrace: {
// ExportClause :
Expand Down
145 changes: 10 additions & 135 deletions test/parser/module/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,6 @@ describe('Module - Export', () => {
});
}

// Namespace export parsing
for (const arg of [

This comment has been minimized.

Copy link
@nchanged

nchanged Nov 6, 2019

Contributor

What is happening here? Why are we ignoring it?

This comment has been minimized.

Copy link
@KFlash

KFlash Nov 7, 2019

Author Contributor

Things changed, and something obviously broke. It's updated in latest commit to Master

"export * as arguments from 'bar'",
"export * as await from 'bar'",
"export * as default from 'bar'",
"export * as enum from 'bar'",
"export * as foo from 'bar'",
"export * as for from 'bar'",
"export * as let from 'bar'",
"export * as static from 'bar'",
"export * as yield from 'bar'"
]) {
it(`${arg}`, () => {
t.doesNotThrow(() => {
parseSource(`${arg}`, undefined, Context.Strict | Context.Module | Context.OptionsNext);
});
});

it(`${arg}`, () => {
t.throws(() => {
parseSource(`${arg}`, undefined, Context.Strict | Context.Module);
});
});
}

// Async await module
for (const arg of [
'export default async function() { await 1; }',
Expand All @@ -70,25 +45,6 @@ describe('Module - Export', () => {
});
}

// Namespace export parsing
for (const arg of [
"export * as arguments from 'bar'",
"export * as await from 'bar'",
"export * as default from 'bar'",
"export * as enum from 'bar'",
"export * as foo from 'bar'",
"export * as for from 'bar'",
"export * as let from 'bar'",
"export * as static from 'bar'",
"export * as yield from 'bar'"
]) {
it(`${arg}`, () => {
t.throws(() => {
parseSource(`${arg}`, undefined, Context.Strict | Context.Module);
});
});
}

for (const arg of [
'export {',
'var a; export { a',
Expand Down Expand Up @@ -117,17 +73,6 @@ describe('Module - Export', () => {
'export { Q } from;',
'export { 123 } from;',
'export { # } from;',
"export default from 'module.js';",
'export * as z from "c";',
"export * as arguments from 'bar'",
"export * as await from 'bar'",
"export * as default from 'bar'",
"export * as enum from 'bar'",
"export * as foo from 'bar'",
"export * as for from 'bar'",
"export * as let from 'bar'",
"export * as static from 'bar'",
"export * as yield from 'bar'",
'export {',
'var a; export { a',
'var a; export { a,',
Expand Down Expand Up @@ -235,22 +180,10 @@ describe('Module - Export', () => {
['export async;', Context.Strict | Context.Module],
['export async () => y', Context.Strict | Context.Module],
['var a; export { a,', Context.Strict | Context.Module],
["export * as class from 'source';", Context.Strict | Context.Module],
['class A extends B { foo() { (super).foo } }', Context.OptionsWebCompat],
['export class extends C {}', Context.None],
['export *;', Context.Strict | Context.Module],
['export * as;', Context.Strict | Context.Module],
['export * as foo;', Context.Strict | Context.Module],
['export * as foo from;', Context.Strict | Context.Module],
["export * as foo from ';", Context.Strict | Context.Module],
["export * as ,foo from 'bar'", Context.Strict | Context.Module],
["export * as default from 'bar'", Context.Strict | Context.Module],
["export * as enum from 'bar'", Context.Strict | Context.Module],
["export * as foo from 'bar'", Context.Strict | Context.Module],
["export * as for from 'bar'", Context.Strict | Context.Module],
["export * as let from 'bar'", Context.Strict | Context.Module],
["export * as static from 'bar'", Context.Strict | Context.Module],
["export * as yield from 'bar'", Context.Strict | Context.Module],
[
'var x; export { x as z }; export * as z from "string";',
Context.Strict | Context.Module | Context.OptionsLexical
Expand Down Expand Up @@ -284,8 +217,6 @@ describe('Module - Export', () => {
['(function() { export default null; });', Context.Strict | Context.Module],
['for (x = 0; false;) export default null;', Context.Strict | Context.Module],
['do export default null; while (false)', Context.Strict | Context.Module],
["export * as arguments from 'bar'", Context.Strict | Context.Module],
["export * as await from 'bar'", Context.Strict | Context.Module],
['export default async x \n() => {}', Context.Strict | Context.Module],
['{export default 3}', Context.Strict | Context.Module],
['while (1) export default 3', Context.Strict | Context.Module],
Expand Down Expand Up @@ -1016,50 +947,28 @@ describe('Module - Export', () => {
type: 'Program'
}
],
[
'export * from "foo"',
Context.Module | Context.OptionsRanges,
{
type: 'Program',
start: 0,
end: 19,
body: [
{
type: 'ExportAllDeclaration',
start: 0,
end: 19,
source: {
type: 'Literal',
start: 14,
end: 19,
value: 'foo'
}
}
],
sourceType: 'module'
}
],
[
'export * from "a"',
Context.Module | Context.Strict | Context.OptionsNext | Context.OptionsRanges,
{
type: 'Program',
start: 0,
end: 17,
body: [
{
type: 'ExportAllDeclaration',
start: 0,
end: 17,
source: {
type: 'Literal',
start: 14,
end: 17,
start: 14,
type: 'Literal',
value: 'a'
}
},
specifiers: [],
start: 0,
type: 'ExportNamedDeclaration'
}
],
sourceType: 'module'
end: 17,
sourceType: 'module',
start: 0,
type: 'Program'
}
],
[
Expand Down Expand Up @@ -2694,23 +2603,6 @@ describe('Module - Export', () => {
]
}
],
[
'export * from "foo";',
Context.Strict | Context.Module,
{
type: 'Program',
sourceType: 'module',
body: [
{
type: 'ExportAllDeclaration',
source: {
type: 'Literal',
value: 'foo'
}
}
]
}
],
[
'export default function () {}',
Context.Strict | Context.Module,
Expand Down Expand Up @@ -3483,23 +3375,6 @@ describe('Module - Export', () => {
]
}
],
[
'export * from "foo"',
Context.Strict | Context.Module,
{
type: 'Program',
body: [
{
type: 'ExportAllDeclaration',
source: {
type: 'Literal',
value: 'foo'
}
}
],
sourceType: 'module'
}
],
[
'export {}',
Context.Strict | Context.Module,
Expand Down

0 comments on commit 01db03c

Please sign in to comment.