From 1b11cf443653c3302fa1d70e6ba35252b6b426c3 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Sat, 26 Oct 2024 15:15:47 +0100 Subject: [PATCH] refactor(napi): move custom types to bottom of file --- npm/oxc-types/types.d.ts | 66 ++++++++++---------- tasks/ast_tools/src/generators/typescript.rs | 5 +- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/npm/oxc-types/types.d.ts b/npm/oxc-types/types.d.ts index f6593320727da0..db0afb64ee7411 100644 --- a/npm/oxc-types/types.d.ts +++ b/npm/oxc-types/types.d.ts @@ -1,39 +1,6 @@ // Auto-generated code, DO NOT EDIT DIRECTLY! // To edit this generated file you have to edit `tasks/ast_tools/src/generators/typescript.rs` -export interface FormalParameterRest extends Span { - type: 'RestElement'; - argument: BindingPatternKind; - typeAnnotation: TSTypeAnnotation | null; - optional: boolean; -} - -export type RegExpFlags = { - /** Global flag */ - G: 1; - /** Ignore case flag */ - I: 2; - /** Multiline flag */ - M: 4; - /** DotAll flag */ - S: 8; - /** Unicode flag */ - U: 16; - /** Sticky flag */ - Y: 32; - /** Indices flag */ - D: 64; - /** Unicode sets flag */ - V: 128; -}; - -export type JSXElementName = - | JSXIdentifier - | JSXNamespacedName - | JSXMemberExpression; - -export type JSXMemberExpressionObject = JSXIdentifier | JSXMemberExpression; - export interface BooleanLiteral extends Span { type: 'BooleanLiteral'; value: boolean; @@ -2008,3 +1975,36 @@ export interface NamedReference extends Span { type: 'NamedReference'; name: string; } + +export interface FormalParameterRest extends Span { + type: 'RestElement'; + argument: BindingPatternKind; + typeAnnotation: TSTypeAnnotation | null; + optional: boolean; +} + +export type RegExpFlags = { + /** Global flag */ + G: 1; + /** Ignore case flag */ + I: 2; + /** Multiline flag */ + M: 4; + /** DotAll flag */ + S: 8; + /** Unicode flag */ + U: 16; + /** Sticky flag */ + Y: 32; + /** Indices flag */ + D: 64; + /** Unicode sets flag */ + V: 128; +}; + +export type JSXElementName = + | JSXIdentifier + | JSXNamespacedName + | JSXMemberExpression; + +export type JSXMemberExpressionObject = JSXIdentifier | JSXMemberExpression; diff --git a/tasks/ast_tools/src/generators/typescript.rs b/tasks/ast_tools/src/generators/typescript.rs index a71edf51b351c7..4d61f384412090 100644 --- a/tasks/ast_tools/src/generators/typescript.rs +++ b/tasks/ast_tools/src/generators/typescript.rs @@ -21,8 +21,7 @@ define_generator!(TypescriptGenerator); impl Generator for TypescriptGenerator { fn generate(&mut self, ctx: &LateCtx) -> Output { - let mut code = format!("{CUSTOM_TYPESCRIPT}\n"); - + let mut code = String::new(); for def in ctx.schema() { if !def.generates_derive("ESTree") { continue; @@ -37,6 +36,8 @@ impl Generator for TypescriptGenerator { code.push_str("\n\n"); } + code.push_str(CUSTOM_TYPESCRIPT); + Output::Javascript { path: format!("{}/types.d.ts", crate::TYPESCRIPT_PACKAGE), code } } }