diff --git a/package-lock.json b/package-lock.json index cfb42a4..5286f1f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@knighted/reparse", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@knighted/reparse", - "version": "1.1.0", + "version": "1.2.0", "license": "MIT", "dependencies": { "@swc/core": "^1.5.24" diff --git a/package.json b/package.json index 0de42c0..0a9e3a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@knighted/reparse", - "version": "1.1.0", + "version": "1.2.0", "description": "Multiple swc parsings of the same file with correct spans.", "type": "module", "main": "dist/reparse.js", diff --git a/src/child.js b/src/child.js index beca001..c319417 100644 --- a/src/child.js +++ b/src/child.js @@ -5,7 +5,7 @@ import { parseSync, parseFileSync } from '@swc/core' const baseConfig = { comments: false, target: 'esnext', - isModule: true, + isModule: 'unknown', } const tsConfig = { syntax: 'typescript', diff --git a/src/childSync.js b/src/childSync.js index d3e87a1..a7e162b 100644 --- a/src/childSync.js +++ b/src/childSync.js @@ -5,7 +5,7 @@ import { parseSync, parseFileSync } from '@swc/core' const baseConfig = { comments: false, target: 'esnext', - isModule: true, + isModule: 'unknown', } const tsConfig = { syntax: 'typescript', diff --git a/src/reparse.ts b/src/reparse.ts index 41d63c7..1e49467 100644 --- a/src/reparse.ts +++ b/src/reparse.ts @@ -1,12 +1,12 @@ import { fork, spawnSync } from 'node:child_process' import { join } from 'node:path' -import type { Module } from '@swc/core' +import type { Module, Script } from '@swc/core' type Lang = 'ts' | 'es' -const isModule = (msg: unknown): msg is Module => { - if (msg && typeof msg === 'object' && 'type' in msg && msg.type === 'Module') { +const isModuleOrScript = (msg: unknown): msg is Module | Script => { + if (msg && typeof msg === 'object' && 'type' in msg && (msg.type === 'Module' || msg.type === 'Script')) { return true } @@ -17,9 +17,9 @@ const forkChild = (...args: string[]) => { serialization: 'advanced', }) - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { child.on('message', msg => { - if (isModule(msg)) { + if (isModuleOrScript(msg)) { resolve(msg) }