Oxc Parser
Features
Fast Mode
By default, Oxc parser does not produce semantic errors where symbols and scopes are needed.
To enable semantic errors, apply the option showSemanticErrors: true
.
For example,
let foo;
let foo;
Does not produce any errors when showSemanticErrors
is false
, which is the default behavior.
This mode is best suited for parser plugins, where other parts of your build pipeline has already checked for errors.
Returns ESM information.
It is likely that you are writing a parser plugin that requires ESM information.
To avoid walking the AST again, Oxc Parser returns ESM information directly.
This information can be used to rewrite import and exports with the help of magic-string
,
without any AST manipulations.
export interface EcmaScriptModule {
hasModuleSyntax: boolean;
staticImports: Array<StaticImport>;
staticExports: Array<StaticExport>;
dynamicImports: Array<DynamicImport>;
importMetas: Array<Span>;
}
API
import oxc from './index.js';
const code = 'const url: String = /* 🤨 */ import.meta.url;';
const filename = 'test.tsx';
const result = oxc.parseSync(filename, code);
console.log(result.errors);
console.log(result.program, result.comments);
console.log(result.module);