Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parsing of imports with module string name in flow plugin (#12224)
- Loading branch information
1 parent
136bf23
commit f1bc314
Showing
10 changed files
with
242 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/flow/module-string-names/default-import/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import {"default" as quotation} from "Confucius"; |
48 changes: 48 additions & 0 deletions
48
packages/babel-parser/test/fixtures/flow/module-string-names/default-import/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":49,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":49}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":49,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":49}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ImportDeclaration", | ||
"start":0,"end":49,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":49}}, | ||
"specifiers": [ | ||
{ | ||
"type": "ImportSpecifier", | ||
"start":8,"end":30,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":30}}, | ||
"imported": { | ||
"type": "StringLiteral", | ||
"start":8,"end":17,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":17}}, | ||
"extra": { | ||
"rawValue": "default", | ||
"raw": "\"default\"" | ||
}, | ||
"value": "default" | ||
}, | ||
"importKind": null, | ||
"local": { | ||
"type": "Identifier", | ||
"start":21,"end":30,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":30},"identifierName":"quotation"}, | ||
"name": "quotation" | ||
} | ||
} | ||
], | ||
"importKind": "value", | ||
"source": { | ||
"type": "StringLiteral", | ||
"start":37,"end":48,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":48}}, | ||
"extra": { | ||
"rawValue": "Confucius", | ||
"raw": "\"Confucius\"" | ||
}, | ||
"value": "Confucius" | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/flow/module-string-names/import-local-is-string/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import { "foo" } from "baz"; |
8 changes: 8 additions & 0 deletions
8
...s/babel-parser/test/fixtures/flow/module-string-names/import-local-is-string/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"sourceType": "module", | ||
"plugins": [ | ||
"moduleStringNames", | ||
"flow" | ||
], | ||
"throws": "A string literal cannot be used as an imported binding.\n- Did you mean `import { \"foo\" as foo }`? (1:9)" | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/babel-parser/test/fixtures/flow/module-string-names/mixed/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { "foo" as bar, "default" as qux } from "module-a"; | ||
export * as "foo", { default as "quux" } from "module-b"; |
115 changes: 115 additions & 0 deletions
115
packages/babel-parser/test/fixtures/flow/module-string-names/mixed/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":116,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":57}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":116,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":57}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ImportDeclaration", | ||
"start":0,"end":58,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":58}}, | ||
"specifiers": [ | ||
{ | ||
"type": "ImportSpecifier", | ||
"start":9,"end":21,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":21}}, | ||
"imported": { | ||
"type": "StringLiteral", | ||
"start":9,"end":14,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":14}}, | ||
"extra": { | ||
"rawValue": "foo", | ||
"raw": "\"foo\"" | ||
}, | ||
"value": "foo" | ||
}, | ||
"importKind": null, | ||
"local": { | ||
"type": "Identifier", | ||
"start":18,"end":21,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":21},"identifierName":"bar"}, | ||
"name": "bar" | ||
} | ||
}, | ||
{ | ||
"type": "ImportSpecifier", | ||
"start":23,"end":39,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":39}}, | ||
"imported": { | ||
"type": "StringLiteral", | ||
"start":23,"end":32,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":32}}, | ||
"extra": { | ||
"rawValue": "default", | ||
"raw": "\"default\"" | ||
}, | ||
"value": "default" | ||
}, | ||
"importKind": null, | ||
"local": { | ||
"type": "Identifier", | ||
"start":36,"end":39,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":39},"identifierName":"qux"}, | ||
"name": "qux" | ||
} | ||
} | ||
], | ||
"importKind": "value", | ||
"source": { | ||
"type": "StringLiteral", | ||
"start":47,"end":57,"loc":{"start":{"line":1,"column":47},"end":{"line":1,"column":57}}, | ||
"extra": { | ||
"rawValue": "module-a", | ||
"raw": "\"module-a\"" | ||
}, | ||
"value": "module-a" | ||
} | ||
}, | ||
{ | ||
"type": "ExportNamedDeclaration", | ||
"start":59,"end":116,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":57}}, | ||
"specifiers": [ | ||
{ | ||
"type": "ExportNamespaceSpecifier", | ||
"start":66,"end":76,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":17}}, | ||
"exported": { | ||
"type": "StringLiteral", | ||
"start":71,"end":76,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":17}}, | ||
"extra": { | ||
"rawValue": "foo", | ||
"raw": "\"foo\"" | ||
}, | ||
"value": "foo" | ||
} | ||
}, | ||
{ | ||
"type": "ExportSpecifier", | ||
"start":80,"end":97,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":38}}, | ||
"local": { | ||
"type": "Identifier", | ||
"start":80,"end":87,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":28},"identifierName":"default"}, | ||
"name": "default" | ||
}, | ||
"exported": { | ||
"type": "StringLiteral", | ||
"start":91,"end":97,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":38}}, | ||
"extra": { | ||
"rawValue": "quux", | ||
"raw": "\"quux\"" | ||
}, | ||
"value": "quux" | ||
} | ||
} | ||
], | ||
"source": { | ||
"type": "StringLiteral", | ||
"start":105,"end":115,"loc":{"start":{"line":2,"column":46},"end":{"line":2,"column":56}}, | ||
"extra": { | ||
"rawValue": "module-b", | ||
"raw": "\"module-b\"" | ||
}, | ||
"value": "module-b" | ||
}, | ||
"declaration": null, | ||
"exportKind": "value" | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/flow/module-string-names/named-imports/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import {"學而時習之,不亦說乎?" as quotation} from "Confucius"; |
48 changes: 48 additions & 0 deletions
48
packages/babel-parser/test/fixtures/flow/module-string-names/named-imports/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":53}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":53}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ImportDeclaration", | ||
"start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":53}}, | ||
"specifiers": [ | ||
{ | ||
"type": "ImportSpecifier", | ||
"start":8,"end":34,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":34}}, | ||
"imported": { | ||
"type": "StringLiteral", | ||
"start":8,"end":21,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":21}}, | ||
"extra": { | ||
"rawValue": "學而時習之,不亦說乎?", | ||
"raw": "\"學而時習之,不亦說乎?\"" | ||
}, | ||
"value": "學而時習之,不亦說乎?" | ||
}, | ||
"importKind": null, | ||
"local": { | ||
"type": "Identifier", | ||
"start":25,"end":34,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":34},"identifierName":"quotation"}, | ||
"name": "quotation" | ||
} | ||
} | ||
], | ||
"importKind": "value", | ||
"source": { | ||
"type": "StringLiteral", | ||
"start":41,"end":52,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":52}}, | ||
"extra": { | ||
"rawValue": "Confucius", | ||
"raw": "\"Confucius\"" | ||
}, | ||
"value": "Confucius" | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/babel-parser/test/fixtures/flow/module-string-names/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"sourceType": "module", | ||
"plugins": ["flow", "moduleStringNames"] | ||
} |