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:
Daiki Nishikawa 2023-02-08 00:18:10 +09:00 committed by GitHub
parent e65699c755
commit 76bc8a2974
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 270 additions and 1 deletions

View File

@ -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

View File

@ -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())),

View File

@ -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!(

View File

@ -0,0 +1,3 @@
const path = require('path');
console.log("hello, world!");

View 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
}

View File

@ -0,0 +1,3 @@
import path from "node:path";
console.log("hello, world!");

View 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
}