Skip to content
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

feat(cli): Support for *.mts/*.cts files #6909

Merged
merged 9 commits into from Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/swc_cli/src/commands/compile.rs
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions crates/swc/src/config/mod.rs
Expand Up @@ -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())),
Expand Down
2 changes: 2 additions & 0 deletions crates/swc_ecma_parser/tests/typescript.rs
Expand Up @@ -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!(
Expand Down
3 changes: 3 additions & 0 deletions crates/swc_ecma_parser/tests/typescript/cts/1.cts
@@ -0,0 +1,3 @@
const path = require('path');

console.log("hello, world!");
137 changes: 137 additions & 0 deletions crates/swc_ecma_parser/tests/typescript/cts/1.cts.json
@@ -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 changes: 3 additions & 0 deletions crates/swc_ecma_parser/tests/typescript/mts/1.mts
@@ -0,0 +1,3 @@
import path from "node:path";

console.log("hello, world!");
111 changes: 111 additions & 0 deletions crates/swc_ecma_parser/tests/typescript/mts/1.mts.json
@@ -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
}