-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Describe the bug
Having a windows path in a variable returns part of path segment have duplicated backslash, output ast is
{
"type": "Module",
"span": {
"start": 0,
"end": 108
},
"body": [
{
"type": "VariableDeclaration",
"span": {
"start": 0,
"end": 108
},
"ctxt": 0,
"kind": "var",
"declare": false,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 4,
"end": 108
},
"id": {
"type": "Identifier",
"span": {
"start": 4,
"end": 16
},
"ctxt": 2,
"value": "coverageData",
"optional": false,
"typeAnnotation": null
},
"init": {
"type": "ObjectExpression",
"span": {
"start": 19,
"end": 108
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 26,
"end": 30
},
"value": "path"
},
"value": {
"type": "StringLiteral",
"span": {
"start": 32,
"end": 101
},
"value": "C:\\github\\swc-plugin-coverage-instrument\\spec\\\\util\\verifier.ts",
"raw": "\"C:\\\\github\\\\swc-plugin-coverage-instrument\\\\spec\\\\util\\\\verifier.ts\""
}
}
]
},
"definite": false
}
]
}
],
"interpreter": null
}
the relavant node is
"value": {
"type": "StringLiteral",
"span": {
"start": 32,
"end": 101
},
"value": "C:\\github\\swc-plugin-coverage-instrument\\spec\\\\util\\verifier.ts",
"raw": "\"C:\\\\github\\\\swc-plugin-coverage-instrument\\\\spec\\\\util\\\\verifier.ts\""
}
in value, there's spec\\\\util while all others are \\.
Input code
var coverageData = {
path: "C:\\github\\swc-plugin-coverage-instrument\\spec\\util\\verifier.ts",
}Config
Default ast parser config in playgroundLink to the code that reproduces this issue
SWC Info output
Operating System:
Platform: win32
Arch: x64
Machine Type: x86_64
Version: Windows 11 Pro
CPU: (8 cores)
Models: Snapdragon (TM) 8cx Gen 3 @ 3.0 GHz
Binaries:
Node: 25.1.0
npm: 11.6.2
Yarn: N/A
pnpm: N/A
Relevant Packages:
@swc/core: 1.14.0
@swc/helpers: N/A
@swc/types: 0.1.25
typescript: 5.5.3
SWC Config:
output: N/A
.swcrc path: N/A
Next.js info:
output: N/A
Expected behavior
expect "value": "C:\\github\\swc-plugin-coverage-instrument\\spec\\util\\verifier.ts",
Actual behavior
value output have inconsistent backslash
"value": "C:\\github\\swc-plugin-coverage-instrument\\spec\\\\util\\verifier.ts",
Version
1.14.0
Additional context
No response