Skip to content

Commit

Permalink
maintain estree string literal shape when cloned
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Dec 9, 2021
1 parent 94af0e5 commit 937365c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
8 changes: 8 additions & 0 deletions packages/babel-parser/src/plugins/estree.js
Expand Up @@ -108,6 +108,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
node.expression = false;
}

cloneStringLiteral(node: any): any {
const cloned = super.cloneStringLiteral(node);
cloned.type = "Literal";
cloned.raw = cloned.extra.raw;
delete cloned.extra;
return cloned;
}

checkDeclaration(node: N.Pattern | N.ObjectProperty): void {
if (node != null && this.isObjectProperty(node)) {
this.checkDeclaration(((node: any): N.EstreeProperty).value);
Expand Down

This file was deleted.

@@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["flow", "jsx", "estree"]
}
@@ -0,0 +1 @@
export { "foo" } from "module-a";
@@ -0,0 +1,41 @@
{
"type": "File",
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},
"program": {
"type": "Program",
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExportNamedDeclaration",
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},
"specifiers": [
{
"type": "ExportSpecifier",
"start":9,"end":14,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":14}},
"local": {
"type": "Literal",
"start":9,"end":14,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":14}},
"value": "foo",
"raw": "\"foo\""
},
"exported": {
"type": "StringLiteral",
"start":9,"end":14,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":14}},
"value": "foo"
}
}
],
"source": {
"type": "Literal",
"start":22,"end":32,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":32}},
"value": "module-a",
"raw": "\"module-a\""
},
"declaration": null,
"exportKind": "value"
}
]
}
}

0 comments on commit 937365c

Please sign in to comment.