New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow import attributes for TSImportType
#16277
Changes from 5 commits
ff65f51
76e2aa7
a4a41ce
e9a4cdc
d3d852b
950a377
c0dafaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -566,6 +566,16 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) => | |||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
// For compatibility to estree we cannot call parseLiteral directly here | ||||||||||||||||||||||||||||||||||||||||||||||
node.argument = super.parseExprAtom() as N.StringLiteral; | ||||||||||||||||||||||||||||||||||||||||||||||
if (this.hasPlugin("importAttributes")) { | ||||||||||||||||||||||||||||||||||||||||||||||
node.options = null; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
if (this.eat(tt.comma)) { | ||||||||||||||||||||||||||||||||||||||||||||||
this.expectImportAttributesPlugin(); | ||||||||||||||||||||||||||||||||||||||||||||||
if (!this.match(tt.parenR)) { | ||||||||||||||||||||||||||||||||||||||||||||||
node.options = super.parseMaybeAssignAllowIn(); | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I implemented the same logic as babel/packages/babel-parser/src/parser/expression.ts Lines 2952 to 2973 in 19c54cf
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That looks good to me. We can add a new test case for integration with the JSX plugin, e.g. typeof import("foo.json", <ImportOptionBagJSX type="json"/>) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added tests but it is invalid ( 950a377 ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we fix it in this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessary. The input is a purely imaginative case so I think we can defer the fix to the future. |
||||||||||||||||||||||||||||||||||||||||||||||
this.eat(tt.comma); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
this.expect(tt.parenR); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
if (this.eat(tt.dot)) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let x: typeof import('./x', { with: { type: "json" }}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
"typescript", | ||
"importAttributes" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":55,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":55,"index":55}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":55,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":55,"index":55}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "VariableDeclaration", | ||
"start":0,"end":55,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":55,"index":55}}, | ||
"declarations": [ | ||
{ | ||
"type": "VariableDeclarator", | ||
"start":4,"end":54,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":54,"index":54}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":4,"end":54,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":54,"index":54},"identifierName":"x"}, | ||
"name": "x", | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":5,"end":54,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":54,"index":54}}, | ||
"typeAnnotation": { | ||
"type": "TSTypeQuery", | ||
"start":7,"end":54,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":54,"index":54}}, | ||
"exprName": { | ||
"type": "TSImportType", | ||
"start":14,"end":54,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":54,"index":54}}, | ||
"argument": { | ||
"type": "StringLiteral", | ||
"start":21,"end":26,"loc":{"start":{"line":1,"column":21,"index":21},"end":{"line":1,"column":26,"index":26}}, | ||
"extra": { | ||
"rawValue": "./x", | ||
"raw": "'./x'" | ||
}, | ||
"value": "./x" | ||
}, | ||
"options": { | ||
"type": "ObjectExpression", | ||
"start":28,"end":53,"loc":{"start":{"line":1,"column":28,"index":28},"end":{"line":1,"column":53,"index":53}}, | ||
"properties": [ | ||
{ | ||
"type": "ObjectProperty", | ||
"start":30,"end":52,"loc":{"start":{"line":1,"column":30,"index":30},"end":{"line":1,"column":52,"index":52}}, | ||
"method": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":30,"end":34,"loc":{"start":{"line":1,"column":30,"index":30},"end":{"line":1,"column":34,"index":34},"identifierName":"with"}, | ||
"name": "with" | ||
}, | ||
"computed": false, | ||
"shorthand": false, | ||
"value": { | ||
"type": "ObjectExpression", | ||
"start":36,"end":52,"loc":{"start":{"line":1,"column":36,"index":36},"end":{"line":1,"column":52,"index":52}}, | ||
"properties": [ | ||
{ | ||
"type": "ObjectProperty", | ||
"start":38,"end":50,"loc":{"start":{"line":1,"column":38,"index":38},"end":{"line":1,"column":50,"index":50}}, | ||
"method": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":38,"end":42,"loc":{"start":{"line":1,"column":38,"index":38},"end":{"line":1,"column":42,"index":42},"identifierName":"type"}, | ||
"name": "type" | ||
}, | ||
"computed": false, | ||
"shorthand": false, | ||
"value": { | ||
"type": "StringLiteral", | ||
"start":44,"end":50,"loc":{"start":{"line":1,"column":44,"index":44},"end":{"line":1,"column":50,"index":50}}, | ||
"extra": { | ||
"rawValue": "json", | ||
"raw": "\"json\"" | ||
}, | ||
"value": "json" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"init": null | ||
} | ||
], | ||
"kind": "let" | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 569 only checks for the
importAttributes
plugin, but line 573 checks for both. I'm fine with doing either, but we should be consistent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed c0dafaa