-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node/swc): Support
sourceFileName
(#1976)
swc: - Support `sourceFileName`.
- Loading branch information
Showing
21 changed files
with
4,607 additions
and
21 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 React from "react"; | ||
const comp = () => <amp-something className="something" />; |
164 changes: 164 additions & 0 deletions
164
ecmascript/parser/tests/typescript/next/0001/input.tsx.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,164 @@ | ||
{ | ||
"type": "Module", | ||
"span": { | ||
"start": 0, | ||
"end": 86, | ||
"ctxt": 0 | ||
}, | ||
"body": [ | ||
{ | ||
"type": "ImportDeclaration", | ||
"span": { | ||
"start": 0, | ||
"end": 26, | ||
"ctxt": 0 | ||
}, | ||
"specifiers": [ | ||
{ | ||
"type": "ImportDefaultSpecifier", | ||
"span": { | ||
"start": 7, | ||
"end": 12, | ||
"ctxt": 0 | ||
}, | ||
"local": { | ||
"type": "Identifier", | ||
"span": { | ||
"start": 7, | ||
"end": 12, | ||
"ctxt": 0 | ||
}, | ||
"value": "React", | ||
"optional": false | ||
} | ||
} | ||
], | ||
"source": { | ||
"type": "StringLiteral", | ||
"span": { | ||
"start": 18, | ||
"end": 25, | ||
"ctxt": 0 | ||
}, | ||
"value": "react", | ||
"hasEscape": false, | ||
"kind": { | ||
"type": "normal", | ||
"containsQuote": true | ||
} | ||
}, | ||
"typeOnly": false, | ||
"asserts": null | ||
}, | ||
{ | ||
"type": "VariableDeclaration", | ||
"span": { | ||
"start": 27, | ||
"end": 86, | ||
"ctxt": 0 | ||
}, | ||
"kind": "const", | ||
"declare": false, | ||
"declarations": [ | ||
{ | ||
"type": "VariableDeclarator", | ||
"span": { | ||
"start": 33, | ||
"end": 85, | ||
"ctxt": 0 | ||
}, | ||
"id": { | ||
"type": "Identifier", | ||
"span": { | ||
"start": 33, | ||
"end": 37, | ||
"ctxt": 0 | ||
}, | ||
"value": "comp", | ||
"optional": false, | ||
"typeAnnotation": null | ||
}, | ||
"init": { | ||
"type": "ArrowFunctionExpression", | ||
"span": { | ||
"start": 40, | ||
"end": 85, | ||
"ctxt": 0 | ||
}, | ||
"params": [], | ||
"body": { | ||
"type": "JSXElement", | ||
"span": { | ||
"start": 46, | ||
"end": 85, | ||
"ctxt": 0 | ||
}, | ||
"opening": { | ||
"type": "JSXOpeningElement", | ||
"name": { | ||
"type": "Identifier", | ||
"span": { | ||
"start": 47, | ||
"end": 60, | ||
"ctxt": 0 | ||
}, | ||
"value": "amp-something", | ||
"optional": false | ||
}, | ||
"span": { | ||
"start": 46, | ||
"end": 85, | ||
"ctxt": 0 | ||
}, | ||
"attributes": [ | ||
{ | ||
"type": "JSXAttribute", | ||
"span": { | ||
"start": 61, | ||
"end": 82, | ||
"ctxt": 0 | ||
}, | ||
"name": { | ||
"type": "Identifier", | ||
"span": { | ||
"start": 61, | ||
"end": 70, | ||
"ctxt": 0 | ||
}, | ||
"value": "className", | ||
"optional": false | ||
}, | ||
"value": { | ||
"type": "StringLiteral", | ||
"span": { | ||
"start": 71, | ||
"end": 82, | ||
"ctxt": 0 | ||
}, | ||
"value": "something", | ||
"hasEscape": false, | ||
"kind": { | ||
"type": "normal", | ||
"containsQuote": true | ||
} | ||
} | ||
} | ||
], | ||
"selfClosing": true, | ||
"typeArguments": null | ||
}, | ||
"children": [], | ||
"closing": null | ||
}, | ||
"async": false, | ||
"generator": false, | ||
"typeParameters": null, | ||
"returnType": null | ||
}, | ||
"definite": false | ||
} | ||
] | ||
} | ||
], | ||
"interpreter": null | ||
} |
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
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
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,40 @@ | ||
use swc_ecma_ast::*; | ||
use swc_ecma_parser::{EsConfig, Syntax}; | ||
use swc_ecma_transforms_testing::test_transform; | ||
use swc_ecma_visit::Fold; | ||
|
||
struct Panicking; | ||
|
||
impl Fold for Panicking { | ||
fn fold_jsx_opening_element(&mut self, node: JSXOpeningElement) -> JSXOpeningElement { | ||
let JSXOpeningElement { name, .. } = &node; | ||
println!("HMM"); | ||
|
||
if let JSXElementName::Ident(Ident { sym, .. }) = name { | ||
panic!("visited: {}", sym) | ||
} | ||
|
||
JSXOpeningElement { ..node } | ||
} | ||
} | ||
|
||
#[test] | ||
#[should_panic = "visited"] | ||
fn ensure_visited() { | ||
test_transform( | ||
Syntax::Es(EsConfig { | ||
jsx: true, | ||
..Default::default() | ||
}), | ||
|_| Panicking, | ||
" | ||
import React from 'react'; | ||
const comp = () => <amp-something className='something' />; | ||
", | ||
" | ||
import React from 'react'; | ||
const comp = () => <amp-something className='something' />; | ||
", | ||
false, | ||
); | ||
} |
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
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
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
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
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
Oops, something went wrong.