Skip to content

Commit

Permalink
feat: support scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
knightedcodemonkey committed Jun 3, 2024
1 parent 845cef6 commit b6ec28a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parseSync, parseFileSync } from '@swc/core'
const baseConfig = {
comments: false,
target: 'esnext',
isModule: true,
isModule: 'unknown',
}
const tsConfig = {
syntax: 'typescript',
Expand Down
2 changes: 1 addition & 1 deletion src/childSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parseSync, parseFileSync } from '@swc/core'
const baseConfig = {
comments: false,
target: 'esnext',
isModule: true,
isModule: 'unknown',
}
const tsConfig = {
syntax: 'typescript',
Expand Down
10 changes: 5 additions & 5 deletions src/reparse.ts
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -17,9 +17,9 @@ const forkChild = (...args: string[]) => {
serialization: 'advanced',
})

return new Promise<Module>((resolve, reject) => {
return new Promise<Module | Script>((resolve, reject) => {
child.on('message', msg => {
if (isModule(msg)) {
if (isModuleOrScript(msg)) {
resolve(msg)
}

Expand Down

0 comments on commit b6ec28a

Please sign in to comment.