From 5322718f020d1dbb2c6bde3d391d062cfb093b08 Mon Sep 17 00:00:00 2001 From: Sysix Date: Tue, 3 Dec 2024 20:04:50 +0100 Subject: [PATCH] chore(build): run `pnpm run build` --- napi/parser/index.d.ts | 286 ++++++++++++++++++++++++++++++++++++++ napi/transform/index.d.ts | 186 +++++++++++++++++++++++++ napi/transform/index.js | 4 + 3 files changed, 476 insertions(+) diff --git a/napi/parser/index.d.ts b/napi/parser/index.d.ts index ab2164ce2c59e..c0bd22c7009e2 100644 --- a/napi/parser/index.d.ts +++ b/napi/parser/index.d.ts @@ -2,6 +2,18 @@ /* eslint-disable */ export * from '@oxc-project/types'; +export interface ArrowFunctionsOptions { + /** + * This option enables the following: + * * Wrap the generated function in .bind(this) and keeps uses of this inside the function as-is, instead of using a renamed this. + * * Add a runtime check to ensure the functions are not instantiated. + * * Add names to arrow functions. + * + * @default false + */ + spec?: boolean +} + export interface Comment { type: 'Line' | 'Block' value: string @@ -9,6 +21,14 @@ export interface Comment { end: number } +export interface CompilerAssumptions { + ignoreFunctionLength?: boolean + noDocumentAll?: boolean + objectRestNoSymbols?: boolean + pureGetters?: boolean + setPublicClassFields?: boolean +} + export interface EcmaScriptModule { /** Import Statements. */ staticImports: Array @@ -16,6 +36,11 @@ export interface EcmaScriptModule { staticExports: Array } +export interface Es2015Options { + /** Transform arrow functions into function expressions. */ + arrowFunction?: ArrowFunctionsOptions +} + export interface ExportEntry { start: number end: number @@ -131,6 +156,120 @@ export declare const enum ImportNameKind { Default = 'Default' } +export interface IsolatedDeclarationsOptions { + /** + * Do not emit declarations for code that has an @internal annotation in its JSDoc comment. + * This is an internal compiler option; use at your own risk, because the compiler does not check that the result is valid. + * + * Default: `false` + * + * See + */ + stripInternal?: boolean + sourcemap?: boolean +} + +export interface IsolatedDeclarationsResult { + code: string + map?: SourceMap + errors: Array +} + +/** + * Configure how TSX and JSX are transformed. + * + * @see {@link https://babeljs.io/docs/babel-plugin-transform-react-jsx#options} + */ +export interface JsxOptions { + /** + * Decides which runtime to use. + * + * - 'automatic' - auto-import the correct JSX factories + * - 'classic' - no auto-import + * + * @default 'automatic' + */ + runtime?: 'classic' | 'automatic' + /** + * Emit development-specific information, such as `__source` and `__self`. + * + * @default false + * + * @see {@link https://babeljs.io/docs/babel-plugin-transform-react-jsx-development} + */ + development?: boolean + /** + * Toggles whether or not to throw an error if an XML namespaced tag name + * is used. + * + * Though the JSX spec allows this, it is disabled by default since React's + * JSX does not currently have support for it. + * + * @default true + */ + throwIfNamespace?: boolean + /** + * Enables `@babel/plugin-transform-react-pure-annotations`. + * + * It will mark top-level React method calls as pure for tree shaking. + * + * @see {@link https://babeljs.io/docs/en/babel-plugin-transform-react-pure-annotations} + * + * @default true + */ + pure?: boolean + /** + * Replaces the import source when importing functions. + * + * @default 'react' + */ + importSource?: string + /** + * Replace the function used when compiling JSX expressions. It should be a + * qualified name (e.g. `React.createElement`) or an identifier (e.g. + * `createElement`). + * + * Only used for `classic` {@link runtime}. + * + * @default 'React.createElement' + */ + pragma?: string + /** + * Replace the component used when compiling JSX fragments. It should be a + * valid JSX tag name. + * + * Only used for `classic` {@link runtime}. + * + * @default 'React.Fragment' + */ + pragmaFrag?: string + /** + * When spreading props, use `Object.assign` directly instead of an extend helper. + * + * Only used for `classic` {@link runtime}. + * + * @default false + */ + useBuiltIns?: boolean + /** + * When spreading props, use inline object with spread elements directly + * instead of an extend helper or Object.assign. + * + * Only used for `classic` {@link runtime}. + * + * @default false + */ + useSpread?: boolean + /** + * Enable React Fast Refresh . + * + * Conforms to the implementation in {@link https://github.com/facebook/react/tree/v18.3.1/packages/react-refresh} + * + * @default false + */ + refresh?: boolean | ReactRefreshOptions +} + /** * Parse asynchronously. * @@ -171,6 +310,33 @@ export declare function parseSync(filename: string, sourceText: string, options? */ export declare function parseWithoutReturn(filename: string, sourceText: string, options?: ParserOptions | undefined | null): void +export interface ReactRefreshOptions { + /** + * Specify the identifier of the refresh registration variable. + * + * @default `$RefreshReg$`. + */ + refreshReg?: string + /** + * Specify the identifier of the refresh signature variable. + * + * @default `$RefreshSig$`. + */ + refreshSig?: string + emitFullSignatures?: boolean +} + +export interface SourceMap { + file?: string + mappings: string + names: Array + sourceRoot?: string + sources: Array + sourcesContent?: Array + version: number + x_google_ignoreList?: Array +} + export interface StaticExport { start: number end: number @@ -199,6 +365,126 @@ export interface StaticImport { entries: Array } +/** + * Options for transforming a JavaScript or TypeScript file. + * + * @see {@link transform} + */ +export interface TransformOptions { + sourceType?: 'script' | 'module' | 'unambiguous' | undefined + /** Treat the source text as `js`, `jsx`, `ts`, or `tsx`. */ + lang?: 'js' | 'jsx' | 'ts' | 'tsx' + /** + * The current working directory. Used to resolve relative paths in other + * options. + */ + cwd?: string + /** + * Enable source map generation. + * + * When `true`, the `sourceMap` field of transform result objects will be populated. + * + * @default false + * + * @see {@link SourceMap} + */ + sourcemap?: boolean + /** Set assumptions in order to produce smaller output. */ + assumptions?: CompilerAssumptions + /** Configure how TypeScript is transformed. */ + typescript?: TypeScriptOptions + /** Configure how TSX and JSX are transformed. */ + jsx?: JsxOptions + /** + * Sets the target environment for the generated JavaScript. + * + * The lowest target is `es2015`. + * + * Example: + * + * * 'es2015' + * * ['es2020', 'chrome58', 'edge16', 'firefox57', 'node12', 'safari11'] + * + * @default `esnext` (No transformation) + * + * @see [esbuild#target](https://esbuild.github.io/api/#target) + */ + target?: string | Array + /** Define Plugin */ + define?: Record + /** Inject Plugin */ + inject?: Record +} + +export interface TransformResult { + /** + * The transformed code. + * + * If parsing failed, this will be an empty string. + */ + code: string + /** + * The source map for the transformed code. + * + * This will be set if {@link TransformOptions#sourcemap} is `true`. + */ + map?: SourceMap + /** + * The `.d.ts` declaration file for the transformed code. Declarations are + * only generated if `declaration` is set to `true` and a TypeScript file + * is provided. + * + * If parsing failed and `declaration` is set, this will be an empty string. + * + * @see {@link TypeScriptOptions#declaration} + * @see [declaration tsconfig option](https://www.typescriptlang.org/tsconfig/#declaration) + */ + declaration?: string + /** + * Declaration source map. Only generated if both + * {@link TypeScriptOptions#declaration declaration} and + * {@link TransformOptions#sourcemap sourcemap} are set to `true`. + */ + declarationMap?: SourceMap + /** + * Parse and transformation errors. + * + * Oxc's parser recovers from common syntax errors, meaning that + * transformed code may still be available even if there are errors in this + * list. + */ + errors: Array +} + +export interface TypeScriptOptions { + jsxPragma?: string + jsxPragmaFrag?: string + onlyRemoveTypeImports?: boolean + allowNamespaces?: boolean + allowDeclareFields?: boolean + /** + * Also generate a `.d.ts` declaration file for TypeScript files. + * + * The source file must be compliant with all + * [`isolatedDeclarations`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations) + * requirements. + * + * @default false + */ + declaration?: IsolatedDeclarationsOptions + /** + * Rewrite or remove TypeScript import/export declaration extensions. + * + * - When set to `rewrite`, it will change `.ts`, `.mts`, `.cts` extensions to `.js`, `.mjs`, `.cjs` respectively. + * - When set to `remove`, it will remove `.ts`/`.mts`/`.cts`/`.tsx` extension entirely. + * - When set to `true`, it's equivalent to `rewrite`. + * - When set to `false` or omitted, no changes will be made to the extensions. + * + * @default false + */ + rewriteImportExtensions?: 'rewrite' | 'remove' | boolean +} + export interface ValueSpan { value: string start: number diff --git a/napi/transform/index.d.ts b/napi/transform/index.d.ts index 155b71a0a1d13..d1eba49a2579e 100644 --- a/napi/transform/index.d.ts +++ b/napi/transform/index.d.ts @@ -12,6 +12,13 @@ export interface ArrowFunctionsOptions { spec?: boolean } +export interface Comment { + type: 'Line' | 'Block' + value: string + start: number + end: number +} + export interface CompilerAssumptions { ignoreFunctionLength?: boolean noDocumentAll?: boolean @@ -20,11 +27,133 @@ export interface CompilerAssumptions { setPublicClassFields?: boolean } +export interface EcmaScriptModule { + /** Import Statements. */ + staticImports: Array + /** Export Statements. */ + staticExports: Array +} + export interface Es2015Options { /** Transform arrow functions into function expressions. */ arrowFunction?: ArrowFunctionsOptions } +export interface ExportEntry { + start: number + end: number + moduleRequest?: ValueSpan + /** The name under which the desired binding is exported by the module`. */ + importName: ExportImportName + /** The name used to export this binding by this module. */ + exportName: ExportExportName + /** The name that is used to locally access the exported value from within the importing module. */ + localName: ExportLocalName +} + +export interface ExportExportName { + kind: ExportExportNameKind + name?: string + start?: number + end?: number +} + +export declare const enum ExportExportNameKind { + /** `export { name } */ + Name = 'Name', + /** `export default expression` */ + Default = 'Default', + /** `export * from "mod" */ + None = 'None' +} + +export interface ExportImportName { + kind: ExportImportNameKind + name?: string + start?: number + end?: number +} + +export declare const enum ExportImportNameKind { + /** `export { name } */ + Name = 'Name', + /** `export * as ns from "mod"` */ + All = 'All', + /** `export * from "mod"` */ + AllButDefault = 'AllButDefault', + /** Does not have a specifier. */ + None = 'None' +} + +export interface ExportLocalName { + kind: ExportLocalNameKind + name?: string + start?: number + end?: number +} + +export declare const enum ExportLocalNameKind { + /** `export { name } */ + Name = 'Name', + /** `export default expression` */ + Default = 'Default', + /** + * If the exported value is not locally accessible from within the module. + * `export default function () {}` + */ + None = 'None' +} + +export interface ImportEntry { + /** + * The name under which the desired binding is exported by the module. + * + * ```js + * import { foo } from "mod"; + * // ^^^ + * import { foo as bar } from "mod"; + * // ^^^ + * ``` + */ + importName: ImportName + /** + * The name that is used to locally access the imported value from within the importing module. + * ```js + * import { foo } from "mod"; + * // ^^^ + * import { foo as bar } from "mod"; + * // ^^^ + * ``` + */ + localName: ValueSpan + /** + * Whether this binding is for a TypeScript type-only import. + * + * `true` for the following imports: + * ```ts + * import type { foo } from "mod"; + * import { type foo } from "mod"; + * ``` + */ + isType: boolean +} + +export interface ImportName { + kind: ImportNameKind + name?: string + start?: number + end?: number +} + +export declare const enum ImportNameKind { + /** `import { x } from "mod"` */ + Name = 'Name', + /** `import * as ns from "mod"` */ + NamespaceObject = 'NamespaceObject', + /** `import defaultExport from "mod"` */ + Default = 'Default' +} + /** TypeScript Isolated Declarations for Standalone DTS Emit */ export declare function isolatedDeclaration(filename: string, sourceText: string, options?: IsolatedDeclarationsOptions | undefined | null): IsolatedDeclarationsResult @@ -142,6 +271,29 @@ export interface JsxOptions { refresh?: boolean | ReactRefreshOptions } +export interface ParseResult { + program: import("@oxc-project/types").Program + module: EcmaScriptModule + comments: Array + errors: Array +} + +export interface ParserOptions { + sourceType?: 'script' | 'module' | 'unambiguous' | undefined + /** Treat the source text as `js`, `jsx`, `ts`, or `tsx`. */ + lang?: 'js' | 'jsx' | 'ts' | 'tsx' + /** + * Emit `ParenthesizedExpression` in AST. + * + * If this option is true, parenthesized expressions are represented by + * (non-standard) `ParenthesizedExpression` nodes that have a single `expression` property + * containing the expression inside parentheses. + * + * Default: true + */ + preserveParens?: boolean +} + export interface ReactRefreshOptions { /** * Specify the identifier of the refresh registration variable. @@ -169,6 +321,34 @@ export interface SourceMap { x_google_ignoreList?: Array } +export interface StaticExport { + start: number + end: number + entries: Array +} + +export interface StaticImport { + /** Start of import statement. */ + start: number + /** End of import statement. */ + end: number + /** + * Import source. + * + * ```js + * import { foo } from "mod"; + * // ^^^ + * ``` + */ + moduleRequest: ValueSpan + /** + * Import specifiers. + * + * Empty for `import "mod"`. + */ + entries: Array +} + /** * Transpile a JavaScript or TypeScript into a target ECMAScript version. * @@ -303,3 +483,9 @@ export interface TypeScriptOptions { rewriteImportExtensions?: 'rewrite' | 'remove' | boolean } +export interface ValueSpan { + value: string + start: number + end: number +} + diff --git a/napi/transform/index.js b/napi/transform/index.js index e1092b640ae6c..e72b4b135afe9 100644 --- a/napi/transform/index.js +++ b/napi/transform/index.js @@ -361,5 +361,9 @@ if (!nativeBinding) { throw new Error(`Failed to load native binding`) } +module.exports.ExportExportNameKind = nativeBinding.ExportExportNameKind +module.exports.ExportImportNameKind = nativeBinding.ExportImportNameKind +module.exports.ExportLocalNameKind = nativeBinding.ExportLocalNameKind +module.exports.ImportNameKind = nativeBinding.ImportNameKind module.exports.isolatedDeclaration = nativeBinding.isolatedDeclaration module.exports.transform = nativeBinding.transform