mirror of
https://github.com/swc-project/swc.git
synced 2024-11-24 02:06:08 +03:00
feat(bindings/cli): Support for *.mts/*.cts files (#6909)
**Related issue:** - Closes https://github.com/swc-project/swc/issues/4679.
This commit is contained in:
parent
e65699c755
commit
76bc8a2974
@ -121,7 +121,7 @@ static COMPILER: Lazy<Arc<Compiler>> = Lazy::new(|| {
|
||||
});
|
||||
|
||||
/// List of file extensions supported by default.
|
||||
static DEFAULT_EXTENSIONS: &[&str] = &["js", "jsx", "es6", "es", "mjs", "ts", "tsx"];
|
||||
static DEFAULT_EXTENSIONS: &[&str] = &["js", "jsx", "es6", "es", "mjs", "ts", "tsx", "cts", "mts"];
|
||||
|
||||
/// Infer list of files to be transformed from cli arguments.
|
||||
/// If given input is a directory, it'll traverse it and collect all supported
|
||||
|
@ -768,6 +768,19 @@ impl Default for Rc {
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
Config {
|
||||
env: None,
|
||||
test: Some(FileMatcher::Regex("\\.(cts|mts)$".into())),
|
||||
exclude: None,
|
||||
jsc: JscConfig {
|
||||
syntax: Some(Syntax::Typescript(TsConfig {
|
||||
tsx: false,
|
||||
..Default::default()
|
||||
})),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
Config {
|
||||
env: None,
|
||||
test: Some(FileMatcher::Regex("\\.ts$".into())),
|
||||
|
@ -67,6 +67,8 @@ fn shifted(file: PathBuf) {
|
||||
}
|
||||
|
||||
#[testing::fixture("tests/typescript/**/*.ts")]
|
||||
#[testing::fixture("tests/typescript/**/*.mts")]
|
||||
#[testing::fixture("tests/typescript/**/*.cts")]
|
||||
#[testing::fixture("tests/typescript/**/*.tsx")]
|
||||
fn spec(file: PathBuf) {
|
||||
let output = file.parent().unwrap().join(format!(
|
||||
|
3
crates/swc_ecma_parser/tests/typescript/cts/1.cts
Normal file
3
crates/swc_ecma_parser/tests/typescript/cts/1.cts
Normal file
@ -0,0 +1,3 @@
|
||||
const path = require('path');
|
||||
|
||||
console.log("hello, world!");
|
137
crates/swc_ecma_parser/tests/typescript/cts/1.cts.json
Normal file
137
crates/swc_ecma_parser/tests/typescript/cts/1.cts.json
Normal file
@ -0,0 +1,137 @@
|
||||
{
|
||||
"type": "Script",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 61,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "VariableDeclaration",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 30,
|
||||
"ctxt": 0
|
||||
},
|
||||
"kind": "const",
|
||||
"declare": false,
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"span": {
|
||||
"start": 7,
|
||||
"end": 29,
|
||||
"ctxt": 0
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 7,
|
||||
"end": 11,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "path",
|
||||
"optional": false,
|
||||
"typeAnnotation": null
|
||||
},
|
||||
"init": {
|
||||
"type": "CallExpression",
|
||||
"span": {
|
||||
"start": 14,
|
||||
"end": 29,
|
||||
"ctxt": 0
|
||||
},
|
||||
"callee": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 14,
|
||||
"end": 21,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "require",
|
||||
"optional": false
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"spread": null,
|
||||
"expression": {
|
||||
"type": "StringLiteral",
|
||||
"span": {
|
||||
"start": 22,
|
||||
"end": 28,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "path",
|
||||
"raw": "'path'"
|
||||
}
|
||||
}
|
||||
],
|
||||
"typeArguments": null
|
||||
},
|
||||
"definite": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"span": {
|
||||
"start": 32,
|
||||
"end": 61,
|
||||
"ctxt": 0
|
||||
},
|
||||
"expression": {
|
||||
"type": "CallExpression",
|
||||
"span": {
|
||||
"start": 32,
|
||||
"end": 60,
|
||||
"ctxt": 0
|
||||
},
|
||||
"callee": {
|
||||
"type": "MemberExpression",
|
||||
"span": {
|
||||
"start": 32,
|
||||
"end": 43,
|
||||
"ctxt": 0
|
||||
},
|
||||
"object": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 32,
|
||||
"end": 39,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "console",
|
||||
"optional": false
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 40,
|
||||
"end": 43,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "log",
|
||||
"optional": false
|
||||
}
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"spread": null,
|
||||
"expression": {
|
||||
"type": "StringLiteral",
|
||||
"span": {
|
||||
"start": 44,
|
||||
"end": 59,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "hello, world!",
|
||||
"raw": "\"hello, world!\""
|
||||
}
|
||||
}
|
||||
],
|
||||
"typeArguments": null
|
||||
}
|
||||
}
|
||||
],
|
||||
"interpreter": null
|
||||
}
|
3
crates/swc_ecma_parser/tests/typescript/mts/1.mts
Normal file
3
crates/swc_ecma_parser/tests/typescript/mts/1.mts
Normal file
@ -0,0 +1,3 @@
|
||||
import path from "node:path";
|
||||
|
||||
console.log("hello, world!");
|
111
crates/swc_ecma_parser/tests/typescript/mts/1.mts.json
Normal file
111
crates/swc_ecma_parser/tests/typescript/mts/1.mts.json
Normal file
@ -0,0 +1,111 @@
|
||||
{
|
||||
"type": "Module",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 61,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ImportDeclaration",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 30,
|
||||
"ctxt": 0
|
||||
},
|
||||
"specifiers": [
|
||||
{
|
||||
"type": "ImportDefaultSpecifier",
|
||||
"span": {
|
||||
"start": 8,
|
||||
"end": 12,
|
||||
"ctxt": 0
|
||||
},
|
||||
"local": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 8,
|
||||
"end": 12,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "path",
|
||||
"optional": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"source": {
|
||||
"type": "StringLiteral",
|
||||
"span": {
|
||||
"start": 18,
|
||||
"end": 29,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "node:path",
|
||||
"raw": "\"node:path\""
|
||||
},
|
||||
"typeOnly": false,
|
||||
"asserts": null
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"span": {
|
||||
"start": 32,
|
||||
"end": 61,
|
||||
"ctxt": 0
|
||||
},
|
||||
"expression": {
|
||||
"type": "CallExpression",
|
||||
"span": {
|
||||
"start": 32,
|
||||
"end": 60,
|
||||
"ctxt": 0
|
||||
},
|
||||
"callee": {
|
||||
"type": "MemberExpression",
|
||||
"span": {
|
||||
"start": 32,
|
||||
"end": 43,
|
||||
"ctxt": 0
|
||||
},
|
||||
"object": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 32,
|
||||
"end": 39,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "console",
|
||||
"optional": false
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 40,
|
||||
"end": 43,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "log",
|
||||
"optional": false
|
||||
}
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"spread": null,
|
||||
"expression": {
|
||||
"type": "StringLiteral",
|
||||
"span": {
|
||||
"start": 44,
|
||||
"end": 59,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "hello, world!",
|
||||
"raw": "\"hello, world!\""
|
||||
}
|
||||
}
|
||||
],
|
||||
"typeArguments": null
|
||||
}
|
||||
}
|
||||
],
|
||||
"interpreter": null
|
||||
}
|
Loading…
Reference in New Issue
Block a user