oxc-parser 0.38.0 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,12 +7,11 @@ import assert from 'assert';
7
7
  import oxc from 'oxc-parser';
8
8
 
9
9
  const sourceText = "let foo: Foo = 'foo';";
10
- // Filename extension is used to determine which
11
- // dialect to parse source as
12
- const options = { sourceFilename: 'text.tsx' };
10
+ // Filename extension is used to determine which dialect to parse source as.
11
+ const filename = 'test.tsx';
13
12
 
14
- test(oxc.parseSync(sourceText, options));
15
- test(await oxc.parseAsync(sourceText, options));
13
+ test(oxc.parseSync(filename, sourceText, options));
14
+ test(await oxc.parseAsync(filename, sourceText, options));
16
15
 
17
16
  function test(ret) {
18
17
  assert(ret.program.body.length == 1);
package/bindings.js CHANGED
@@ -361,8 +361,10 @@ if (!nativeBinding) {
361
361
  throw new Error(`Failed to load native binding`)
362
362
  }
363
363
 
364
- module.exports.moduleLexerAsync = nativeBinding.moduleLexerAsync
365
- module.exports.moduleLexerSync = nativeBinding.moduleLexerSync
364
+ module.exports.ExportExportNameKind = nativeBinding.ExportExportNameKind
365
+ module.exports.ExportImportNameKind = nativeBinding.ExportImportNameKind
366
+ module.exports.ExportLocalNameKind = nativeBinding.ExportLocalNameKind
367
+ module.exports.ImportNameKind = nativeBinding.ImportNameKind
366
368
  module.exports.parseAsync = nativeBinding.parseAsync
367
369
  module.exports.parseSync = nativeBinding.parseSync
368
370
  module.exports.parseWithoutReturn = nativeBinding.parseWithoutReturn
package/index.d.ts CHANGED
@@ -9,104 +9,100 @@ export interface Comment {
9
9
  end: number
10
10
  }
11
11
 
12
- export interface ModuleLexer {
13
- imports: Array<ModuleLexerImportSpecifier>
14
- exports: Array<ModuleLexerExportSpecifier>
15
- /**
16
- * ESM syntax detection
17
- *
18
- * The use of ESM syntax: import / export statements and `import.meta`
19
- */
20
- hasModuleSyntax: boolean
21
- /** Facade modules that only use import / export syntax */
22
- facade: boolean
12
+ export interface EcmaScriptModule {
13
+ /** Import Statements. */
14
+ staticImports: Array<StaticImport>
15
+ /** Export Statements. */
16
+ staticExports: Array<StaticExport>
23
17
  }
24
18
 
25
- /**
26
- * # Panics
27
- *
28
- * * Tokio crashes
29
- */
30
- export declare function moduleLexerAsync(sourceText: string, options?: ParserOptions | undefined | null): Promise<ModuleLexer>
31
-
32
- export interface ModuleLexerExportSpecifier {
33
- /** Exported name */
34
- n: string
35
- /** Local name, or undefined. */
36
- ln?: string
37
- /** Start of exported name */
38
- s: number
39
- /** End of exported name */
40
- e: number
41
- /** Start of local name */
42
- ls?: number
43
- /** End of local name */
44
- le?: number
45
- }
46
-
47
- export interface ModuleLexerImportSpecifier {
48
- /**
49
- * Module name
50
- *
51
- * To handle escape sequences in specifier strings, the .n field of imported specifiers will be provided where possible.
52
- *
53
- * For dynamic import expressions, this field will be empty if not a valid JS string.
54
- */
55
- n?: string
56
- /** Start of module specifier */
57
- s: number
58
- /** End of module specifier */
59
- e: number
60
- /** Start of import statement */
61
- ss: number
62
- /** End of import statement */
63
- se: number
64
- /**
65
- * Import Type
66
- * * If this import keyword is a dynamic import, this is the start value.
67
- * * If this import keyword is a static import, this is -1.
68
- * * If this import keyword is an import.meta expression, this is -2.
69
- * * If this import is an `export *`, this is -3.
70
- */
71
- d: number
19
+ export interface ExportExportName {
20
+ kind: ExportExportNameKind
21
+ name?: string
22
+ start?: number
23
+ end?: number
24
+ }
25
+
26
+ export declare const enum ExportExportNameKind {
27
+ /** `export { name } */
28
+ Name = 'Name',
29
+ /** `export default expression` */
30
+ Default = 'Default',
31
+ /** `export * from "mod" */
32
+ None = 'None'
33
+ }
34
+
35
+ export interface ExportImportName {
36
+ kind: ExportImportNameKind
37
+ name?: string
38
+ start?: number
39
+ end?: number
40
+ }
41
+
42
+ export declare const enum ExportImportNameKind {
43
+ /** `export { name } */
44
+ Name = 'Name',
45
+ /** `export * as ns from "mod"` */
46
+ All = 'All',
47
+ /** `export * from "mod"` */
48
+ AllButDefault = 'AllButDefault',
49
+ /** Does not have a specifier. */
50
+ None = 'None'
51
+ }
52
+
53
+ export interface ExportLocalName {
54
+ kind: ExportLocalNameKind
55
+ name?: string
56
+ start?: number
57
+ end?: number
58
+ }
59
+
60
+ export declare const enum ExportLocalNameKind {
61
+ /** `export { name } */
62
+ Name = 'Name',
63
+ /** `export default expression` */
64
+ Default = 'Default',
72
65
  /**
73
- * If this import has an import assertion, this is the start value
74
- * Otherwise this is `-1`.
66
+ * If the exported value is not locally accessible from within the module.
67
+ * `export default function () {}`
75
68
  */
76
- a: number
69
+ None = 'None'
77
70
  }
78
71
 
79
- /**
80
- * Outputs the list of exports and locations of import specifiers,
81
- * including dynamic import and import meta handling.
82
- *
83
- * # Panics
84
- *
85
- * * File extension is invalid
86
- */
87
- export declare function moduleLexerSync(sourceText: string, options?: ParserOptions | undefined | null): ModuleLexer
72
+ export interface ImportName {
73
+ kind: ImportNameKind
74
+ name?: string
75
+ start?: number
76
+ end?: number
77
+ }
78
+
79
+ export declare const enum ImportNameKind {
80
+ /** `import { x } from "mod"` */
81
+ Name = 'Name',
82
+ /** `import * as ns from "mod"` */
83
+ NamespaceObject = 'NamespaceObject',
84
+ /** `import defaultExport from "mod"` */
85
+ Default = 'Default'
86
+ }
88
87
 
89
88
  /**
90
- * # Panics
89
+ * Parse asynchronously.
91
90
  *
92
- * * Tokio crashes
91
+ * Note: This function can be slower than `parseSync` due to the overhead of spawning a thread.
93
92
  */
94
- export declare function parseAsync(sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>
93
+ export declare function parseAsync(filename: string, sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>
95
94
 
96
95
  export interface ParseResult {
97
96
  program: import("@oxc-project/types").Program
97
+ module: EcmaScriptModule
98
98
  comments: Array<Comment>
99
99
  errors: Array<string>
100
100
  }
101
101
 
102
- /**
103
- * Babel Parser Options
104
- *
105
- * <https://github.com/babel/babel/blob/v7.26.2/packages/babel-parser/typings/babel-parser.d.ts>
106
- */
107
102
  export interface ParserOptions {
108
103
  sourceType?: 'script' | 'module' | 'unambiguous' | undefined
109
- sourceFilename?: string
104
+ /** Treat the source text as `js`, `jsx`, `ts`, or `tsx`. */
105
+ lang?: 'js' | 'jsx' | 'ts' | 'tsx'
110
106
  /**
111
107
  * Emit `ParenthesizedExpression` in AST.
112
108
  *
@@ -119,22 +115,93 @@ export interface ParserOptions {
119
115
  preserveParens?: boolean
120
116
  }
121
117
 
122
- /**
123
- * # Panics
124
- *
125
- * * File extension is invalid
126
- * * Serde JSON serialization
127
- */
128
- export declare function parseSync(sourceText: string, options?: ParserOptions | undefined | null): ParseResult
118
+ /** Parse synchronously. */
119
+ export declare function parseSync(filename: string, sourceText: string, options?: ParserOptions | undefined | null): ParseResult
129
120
 
130
121
  /**
131
122
  * Parse without returning anything.
132
- * This is for benchmark purposes such as measuring napi communication overhead.
133
123
  *
134
- * # Panics
135
- *
136
- * * File extension is invalid
137
- * * Serde JSON serialization
124
+ * This is for benchmark purposes such as measuring napi communication overhead.
138
125
  */
139
- export declare function parseWithoutReturn(sourceText: string, options?: ParserOptions | undefined | null): void
126
+ export declare function parseWithoutReturn(filename: string, sourceText: string, options?: ParserOptions | undefined | null): void
127
+
128
+ export interface StaticExport {
129
+ start: number
130
+ end: number
131
+ entries: Array<StaticExportEntry>
132
+ }
133
+
134
+ export interface StaticExportEntry {
135
+ start: number
136
+ end: number
137
+ moduleRequest?: ValueSpan
138
+ /** The name under which the desired binding is exported by the module`. */
139
+ importName: ExportImportName
140
+ /** The name used to export this binding by this module. */
141
+ exportName: ExportExportName
142
+ /** The name that is used to locally access the exported value from within the importing module. */
143
+ localName: ExportLocalName
144
+ }
145
+
146
+ export interface StaticImport {
147
+ /** Start of import statement. */
148
+ start: number
149
+ /** End of import statement. */
150
+ end: number
151
+ /**
152
+ * Import source.
153
+ *
154
+ * ```js
155
+ * import { foo } from "mod";
156
+ * // ^^^
157
+ * ```
158
+ */
159
+ moduleRequest: ValueSpan
160
+ /**
161
+ * Import specifiers.
162
+ *
163
+ * Empty for `import "mod"`.
164
+ */
165
+ entries: Array<StaticImportEntry>
166
+ }
167
+
168
+ export interface StaticImportEntry {
169
+ /**
170
+ * The name under which the desired binding is exported by the module.
171
+ *
172
+ * ```js
173
+ * import { foo } from "mod";
174
+ * // ^^^
175
+ * import { foo as bar } from "mod";
176
+ * // ^^^
177
+ * ```
178
+ */
179
+ importName: ImportName
180
+ /**
181
+ * The name that is used to locally access the imported value from within the importing module.
182
+ * ```js
183
+ * import { foo } from "mod";
184
+ * // ^^^
185
+ * import { foo as bar } from "mod";
186
+ * // ^^^
187
+ * ```
188
+ */
189
+ localName: ValueSpan
190
+ /**
191
+ * Whether this binding is for a TypeScript type-only import.
192
+ *
193
+ * `true` for the following imports:
194
+ * ```ts
195
+ * import type { foo } from "mod";
196
+ * import { type foo } from "mod";
197
+ * ```
198
+ */
199
+ isType: boolean
200
+ }
201
+
202
+ export interface ValueSpan {
203
+ value: string
204
+ start: number
205
+ end: number
206
+ }
140
207
 
package/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  const bindings = require('./bindings.js');
2
2
 
3
- module.exports.moduleLexerAsync = bindings.moduleLexerAsync;
4
- module.exports.moduleLexerSync = bindings.moduleLexerSync;
5
3
  module.exports.parseWithoutReturn = bindings.parseWithoutReturn;
6
4
 
7
5
  module.exports.parseAsync = async function parseAsync(...args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxc-parser",
3
- "version": "0.38.0",
3
+ "version": "0.39.0",
4
4
  "description": "Oxc Parser Node API",
5
5
  "keywords": [
6
6
  "Parser"
@@ -24,16 +24,16 @@
24
24
  "bindings.js"
25
25
  ],
26
26
  "dependencies": {
27
- "@oxc-project/types": "^0.38.0"
27
+ "@oxc-project/types": "^0.39.0"
28
28
  },
29
29
  "optionalDependencies": {
30
- "@oxc-parser/binding-win32-x64-msvc": "0.38.0",
31
- "@oxc-parser/binding-win32-arm64-msvc": "0.38.0",
32
- "@oxc-parser/binding-linux-x64-gnu": "0.38.0",
33
- "@oxc-parser/binding-linux-arm64-gnu": "0.38.0",
34
- "@oxc-parser/binding-linux-x64-musl": "0.38.0",
35
- "@oxc-parser/binding-linux-arm64-musl": "0.38.0",
36
- "@oxc-parser/binding-darwin-x64": "0.38.0",
37
- "@oxc-parser/binding-darwin-arm64": "0.38.0"
30
+ "@oxc-parser/binding-win32-x64-msvc": "0.39.0",
31
+ "@oxc-parser/binding-win32-arm64-msvc": "0.39.0",
32
+ "@oxc-parser/binding-linux-x64-gnu": "0.39.0",
33
+ "@oxc-parser/binding-linux-arm64-gnu": "0.39.0",
34
+ "@oxc-parser/binding-linux-x64-musl": "0.39.0",
35
+ "@oxc-parser/binding-linux-arm64-musl": "0.39.0",
36
+ "@oxc-parser/binding-darwin-x64": "0.39.0",
37
+ "@oxc-parser/binding-darwin-arm64": "0.39.0"
38
38
  }
39
39
  }