oxc-parser 0.51.0 → 0.53.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
@@ -3,8 +3,6 @@
3
3
  ## Features
4
4
 
5
5
  - Returns ESM information.
6
- - Built-in `magic-string` on the Rust side exposed through N-API.
7
- - "clever" approach to overcome the Rust UTF8 vs JavaScript UTF16 length problem.
8
6
 
9
7
  ## Caveat
10
8
 
@@ -19,7 +17,6 @@ where you need quick access to ESM information, as well as fast `magic-string` o
19
17
  ```javascript
20
18
  import oxc from './index.js';
21
19
 
22
- // The emoji makes the span of `import.meta.url` to be different in UTF8 and UTF16.
23
20
  const code = 'const url: String = /* 🤨 */ import.meta.url;';
24
21
 
25
22
  // File extension is used to determine which dialect to parse source as.
@@ -36,16 +33,4 @@ console.log(result.program, result.comments);
36
33
 
37
34
  // ESM information - imports, exports, `import.meta`s.
38
35
  console.log(result.module);
39
-
40
- // A `magic-string` instance for accessing and manipulating the source text.
41
- // All returned spans are in UTF8 offsets, which cannot be used directly on our JavaScript.
42
- // JavaScript string lengths are in UTF16 offsets.
43
- const ms = result.magicString;
44
-
45
- for (const span of result.module.importMetas) {
46
- // Extra methods for access the source text through spans with UTF8 offsets.
47
- console.log(ms.getSourceText(span.start, span.end)); // prints `import.meta`
48
- console.log(ms.getLineColumnNumber(span.start)); // prints `{ line: 0, column: 20 }`
49
- console.log(code.substring(ms.getUtf16ByteOffset(span.start)).startsWith('import.meta.url')); // prints `true`
50
- }
51
36
  ```
package/bindings.js CHANGED
@@ -60,7 +60,13 @@ const isMuslFromChildProcess = () => {
60
60
  }
61
61
 
62
62
  function requireNative() {
63
- if (process.platform === 'android') {
63
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
64
+ try {
65
+ nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
66
+ } catch (err) {
67
+ loadErrors.push(err);
68
+ }
69
+ } else if (process.platform === 'android') {
64
70
  if (process.arch === 'arm64') {
65
71
  try {
66
72
  return require('./parser.android-arm64.node')
@@ -364,7 +370,6 @@ if (!nativeBinding) {
364
370
  throw new Error(`Failed to load native binding`)
365
371
  }
366
372
 
367
- module.exports.MagicString = nativeBinding.MagicString
368
373
  module.exports.ParseResult = nativeBinding.ParseResult
369
374
  module.exports.ExportExportNameKind = nativeBinding.ExportExportNameKind
370
375
  module.exports.ExportImportNameKind = nativeBinding.ExportImportNameKind
package/index.d.ts CHANGED
@@ -2,47 +2,11 @@
2
2
  /* eslint-disable */
3
3
 
4
4
  export * from '@oxc-project/types';
5
- export declare class MagicString {
6
- /** Get source text from utf8 offset. */
7
- getSourceText(start: number, end: number): string
8
- /** Get 0-based line and column number from utf8 offset. */
9
- getLineColumnNumber(offset: number): LineColumn
10
- /** Get UTF16 byte offset from UTF8 byte offset. */
11
- getUtf16ByteOffset(offset: number): number
12
- length(): number
13
- toString(): string
14
- hasChanged(): boolean
15
- append(input: string): this
16
- appendLeft(index: number, input: string): this
17
- appendRight(index: number, input: string): this
18
- indent(): this
19
- prepend(input: string): this
20
- prependLeft(index: number, input: string): this
21
- prependRight(index: number, input: string): this
22
- relocate(start: number, end: number, to: number): this
23
- remove(start: number, end: number): this
24
- generateMap(options?: Partial<GenerateDecodedMapOptions>): {
25
- toString: () => string;
26
- toUrl: () => string;
27
- toMap: () => {
28
- file?: string
29
- mappings: string
30
- names: Array<string>
31
- sourceRoot?: string
32
- sources: Array<string>
33
- sourcesContent?: Array<string>
34
- version: number
35
- x_google_ignoreList?: Array<number>
36
- }
37
- }
38
- }
39
-
40
5
  export declare class ParseResult {
41
6
  get program(): import("@oxc-project/types").Program
42
7
  get module(): EcmaScriptModule
43
8
  get comments(): Array<Comment>
44
9
  get errors(): Array<OxcError>
45
- get magicString(): MagicString
46
10
  }
47
11
 
48
12
  export interface Comment {
@@ -136,15 +100,6 @@ export declare const enum ExportLocalNameKind {
136
100
  None = 'None'
137
101
  }
138
102
 
139
- export interface GenerateDecodedMapOptions {
140
- /** The filename of the file containing the original source. */
141
- source?: string
142
- /** Whether to include the original content in the map's `sourcesContent` array. */
143
- includeContent: boolean
144
- /** Whether the mapping should be high-resolution. */
145
- hires: boolean | 'boundary'
146
- }
147
-
148
103
  export interface ImportName {
149
104
  kind: ImportNameKind
150
105
  name?: string
@@ -161,15 +116,6 @@ export declare const enum ImportNameKind {
161
116
  Default = 'Default'
162
117
  }
163
118
 
164
- export interface LineColumn {
165
- line: number
166
- column: number
167
- }
168
-
169
- export interface OverwriteOptions {
170
- contentOnly: boolean
171
- }
172
-
173
119
  export interface OxcError {
174
120
  severity: Severity
175
121
  message: string
@@ -198,11 +144,6 @@ export interface ParserOptions {
198
144
  * Default: true
199
145
  */
200
146
  preserveParens?: boolean
201
- /**
202
- * Default: false
203
- * @experimental Only for internal usage on Rolldown and Vite.
204
- */
205
- convertSpanUtf16?: boolean
206
147
  }
207
148
 
208
149
  /** Parse synchronously. */
@@ -221,23 +162,6 @@ export declare const enum Severity {
221
162
  Advice = 'Advice'
222
163
  }
223
164
 
224
- export interface SourceMap {
225
- file?: string
226
- mappings: string
227
- names: Array<string>
228
- sourceRoot?: string
229
- sources: Array<string>
230
- sourcesContent?: Array<string>
231
- version: number
232
- x_google_ignoreList?: Array<number>
233
- }
234
-
235
- export interface SourceMapOptions {
236
- includeContent?: boolean
237
- source?: string
238
- hires?: boolean
239
- }
240
-
241
165
  export interface Span {
242
166
  start: number
243
167
  end: number
package/index.js CHANGED
@@ -9,10 +9,12 @@ module.exports.parseWithoutReturn = bindings.parseWithoutReturn;
9
9
  module.exports.Severity = bindings.Severity;
10
10
 
11
11
  function wrap(result) {
12
- let program, module, comments, errors, magicString;
12
+ let program, module, comments, errors;
13
13
  return {
14
14
  get program() {
15
15
  if (!program) {
16
+ // Note: This code is repeated in `wasm/parser/update-bindings.mjs` and `crates/oxc-wasm/update-bindings.mjs`.
17
+ // Any changes should be applied in those 2 scripts too.
16
18
  program = JSON.parse(result.program, function(key, value) {
17
19
  // Set `value` field of `Literal`s for `BigInt`s and `RegExp`s.
18
20
  // This is not possible to do on Rust side, as neither can be represented correctly in JSON.
@@ -46,17 +48,6 @@ function wrap(result) {
46
48
  if (!errors) errors = result.errors;
47
49
  return errors;
48
50
  },
49
- get magicString() {
50
- if (!magicString) magicString = result.magicString;
51
- magicString.generateMap = function generateMap(options) {
52
- return {
53
- toString: () => magicString.toSourcemapString(options),
54
- toUrl: () => magicString.toSourcemapUrl(options),
55
- toMap: () => magicString.toSourcemapObject(options),
56
- };
57
- };
58
- return magicString;
59
- },
60
51
  };
61
52
  }
62
53
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxc-parser",
3
- "version": "0.51.0",
3
+ "version": "0.53.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.51.0"
27
+ "@oxc-project/types": "^0.53.0"
28
28
  },
29
29
  "optionalDependencies": {
30
- "@oxc-parser/binding-win32-x64-msvc": "0.51.0",
31
- "@oxc-parser/binding-win32-arm64-msvc": "0.51.0",
32
- "@oxc-parser/binding-linux-x64-gnu": "0.51.0",
33
- "@oxc-parser/binding-linux-arm64-gnu": "0.51.0",
34
- "@oxc-parser/binding-linux-x64-musl": "0.51.0",
35
- "@oxc-parser/binding-linux-arm64-musl": "0.51.0",
36
- "@oxc-parser/binding-darwin-x64": "0.51.0",
37
- "@oxc-parser/binding-darwin-arm64": "0.51.0"
30
+ "@oxc-parser/binding-win32-x64-msvc": "0.53.0",
31
+ "@oxc-parser/binding-win32-arm64-msvc": "0.53.0",
32
+ "@oxc-parser/binding-linux-x64-gnu": "0.53.0",
33
+ "@oxc-parser/binding-linux-arm64-gnu": "0.53.0",
34
+ "@oxc-parser/binding-linux-x64-musl": "0.53.0",
35
+ "@oxc-parser/binding-linux-arm64-musl": "0.53.0",
36
+ "@oxc-parser/binding-darwin-x64": "0.53.0",
37
+ "@oxc-parser/binding-darwin-arm64": "0.53.0"
38
38
  }
39
39
  }