Skip to content

Commit

Permalink
Commaless import, export
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Oct 13, 2017
1 parent dcfd856 commit 6cd44b3
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,11 @@ pp.parseExportSpecifiers = function () {
if (first) {
first = false;
} else {
this.expect(tt.comma);
if (this.hasPlugin("lightscript")) {
this.expectCommaOrLineBreak();
} else {
this.expect(tt.comma);
}
if (this.eat(tt.braceR)) break;
}

Expand Down Expand Up @@ -1295,7 +1299,11 @@ pp.parseImportSpecifiers = function (node) {
this.unexpected(null, "ES2015 named imports do not destructure. Use another statement for destructuring after the import.");
}

this.expect(tt.comma);
if (this.hasPlugin("lightscript")) {
this.expectCommaOrLineBreak();
} else {
this.expect(tt.comma);
}
if (this.eat(tt.braceR)) break;
}

Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/lightscript/commaless/export/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {
a
b
}
152 changes: 152 additions & 0 deletions test/fixtures/lightscript/commaless/export/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"type": "File",
"start": 0,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ExportNamedDeclaration",
"start": 0,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"declaration": null,
"specifiers": [
{
"type": "ExportSpecifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
}
},
"local": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
},
"identifierName": "a"
},
"name": "a"
},
"exported": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
},
"identifierName": "a"
},
"name": "a"
}
},
{
"type": "ExportSpecifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 3
}
},
"local": {
"type": "Identifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 3
},
"identifierName": "b"
},
"name": "b"
},
"exported": {
"type": "Identifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 3
},
"identifierName": "b"
},
"name": "b"
}
}
],
"source": null,
"exportKind": "value"
}
],
"directives": []
}
}
3 changes: 3 additions & 0 deletions test/fixtures/lightscript/commaless/export/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sourceType": "module"
}
4 changes: 4 additions & 0 deletions test/fixtures/lightscript/commaless/import/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {
a
b
} from 'c'
172 changes: 172 additions & 0 deletions test/fixtures/lightscript/commaless/import/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"type": "File",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 10
}
},
"program": {
"type": "Program",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 10
}
},
"sourceType": "module",
"body": [
{
"type": "ImportDeclaration",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 10
}
},
"specifiers": [
{
"type": "ImportSpecifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
}
},
"imported": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
},
"identifierName": "a"
},
"name": "a"
},
"importKind": null,
"local": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
},
"identifierName": "a"
},
"name": "a"
}
},
{
"type": "ImportSpecifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 3
}
},
"imported": {
"type": "Identifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 3
},
"identifierName": "b"
},
"name": "b"
},
"importKind": null,
"local": {
"type": "Identifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 3
},
"identifierName": "b"
},
"name": "b"
}
}
],
"importKind": "value",
"source": {
"type": "StringLiteral",
"start": 24,
"end": 27,
"loc": {
"start": {
"line": 4,
"column": 7
},
"end": {
"line": 4,
"column": 10
}
},
"extra": {
"rawValue": "c",
"raw": "'c'"
},
"value": "c"
}
}
],
"directives": []
}
}
3 changes: 3 additions & 0 deletions test/fixtures/lightscript/commaless/import/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sourceType": "module"
}

0 comments on commit 6cd44b3

Please sign in to comment.