Skip to content

Commit

Permalink
feat(ast_tools): output typescript to a separate package (#6755)
Browse files Browse the repository at this point in the history
Part of #6347.

Moves typescript logic from derive_estree into a new ast_tools generator.
  • Loading branch information
ottomated committed Oct 24, 2024
1 parent 1c27a2c commit 1145341
Show file tree
Hide file tree
Showing 30 changed files with 2,406 additions and 1,071 deletions.
1 change: 1 addition & 0 deletions .github/.generated_ast_watch_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ src:
- 'crates/oxc_ast/src/generated/ast_builder.rs'
- 'crates/oxc_ast/src/generated/visit.rs'
- 'crates/oxc_ast/src/generated/visit_mut.rs'
- 'npm/oxc-types/src/generated/types.d.ts'
- 'tasks/ast_tools/src/**'
- '.github/.generated_ast_watch_list.yml'
28 changes: 23 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,20 @@ jobs:
with:
cache-key: wasm
save-cache: ${{ github.ref_name == 'main' }}
tools: wasm-pack
tools: wasm-pack,just
- name: Check
run: |
rustup target add wasm32-unknown-unknown
cargo check -p oxc_wasm --target wasm32-unknown-unknown
- uses: ./.github/actions/pnpm
- name: Build
run: |
wasm-pack build --target web --dev ./crates/oxc_wasm
wasm-pack build --target web --dev ./wasm/parser
- uses: ./.github/actions/pnpm
just build-wasm debug
cd ./wasm/parser && pnpm build
- name: Check output types
run: npx -y -p typescript tsc --lib es2020,dom crates/oxc_wasm/pkg/oxc_wasm.d.ts
run: |
pnpm install
npx -y -p typescript tsc --lib es2020,dom npm/oxc-wasm/oxc_wasm.d.ts
typos:
name: Spell Check
Expand Down Expand Up @@ -262,16 +264,32 @@ jobs:
if: steps.filter.outputs.src == 'true'
with:
components: rustfmt
tools: dprint
cache-key: ast_changes
save-cache: ${{ github.ref_name == 'main' }}

- name: Restore dprint plugin cache
id: cache-restore
uses: actions/cache/restore@v4
with:
key: dprint-autofix-ci-${{ runner.os }}-${{ hashFiles('dprint.json') }}
path: ~/.cache/dprint

- name: Check AST Changes
if: steps.filter.outputs.src == 'true'
run: |
cargo run -p oxc_ast_tools
git diff --exit-code ||
(echo 'AST changes caused the "generated" code to get outdated. Have you forgotten to run the `just ast` command and/or commit generated codes?' && exit 1)
- name: Save dprint plugin cache
if: ${{ github.ref_name == 'main' }}
id: cache-save
uses: actions/cache/save@v4
with:
key: ${{ steps.cache-restore.outputs.cache-primary-key }}
path: ~/.cache/dprint

napi:
name: Test NAPI
runs-on: ubuntu-latest
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/release_types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Release @oxc/types

on:
workflow_dispatch:
push:
branches:
- main
paths:
- npm/oxc-types/package.json # Please only commit this file, so we don't need to wait for all the other CI jobs to finish.

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check:
name: Check version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
version_changed: ${{ steps.version.outputs.changed }}
steps:
- uses: taiki-e/checkout-action@v1

- name: Check version changes
uses: EndBug/version-check@v2
id: version
with:
static-checking: localIsNew
file-url: https://unpkg.com/@oxc/types/package.json
file-name: npm/oxc-types/package.json

- name: Set version name
if: steps.version.outputs.changed == 'true'
run: |
echo "Version change found! New version: ${{ steps.version.outputs.version }} (${{ steps.version.outputs.version_type }})"
build:
needs: check
if: needs.check.outputs.version_changed == 'true'
name: Release @oxc/types
runs-on: ubuntu-latest
permissions:
id-token: write # for `pnpm publish --provenance`
steps:
- uses: taiki-e/checkout-action@v1

- uses: ./.github/actions/pnpm

- name: Publish
working-directory: npm/oxc-types
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm publish --provenance --access public
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions crates/oxc_ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ num-bigint = { workspace = true }

serde = { workspace = true, features = ["derive"], optional = true }
serde_json = { workspace = true, optional = true }
wasm-bindgen = { workspace = true, optional = true }

[features]
default = []
serialize = [
"dep:serde",
"dep:serde_json",
"dep:wasm-bindgen",
"oxc_allocator/serialize",
"oxc_regular_expression/serialize",
"oxc_span/serialize",
Expand Down
23 changes: 0 additions & 23 deletions crates/oxc_ast/src/ast/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,26 +190,3 @@ bitflags! {
const V = 1 << 7;
}
}

#[cfg(feature = "serialize")]
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
const TS_APPEND_CONTENT: &'static str = r#"
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
};
"#;
32 changes: 32 additions & 0 deletions crates/oxc_ast/src/ast/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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;
7 changes: 0 additions & 7 deletions crates/oxc_ast/src/ast_impl/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ use oxc_span::Atom;

use crate::ast::*;

#[cfg(feature = "serialize")]
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
const TS_APPEND_CONTENT: &'static str = r#"
export type JSXElementName = JSXIdentifier | JSXNamespacedName | JSXMemberExpression;
export type JSXMemberExpressionObject = JSXIdentifier | JSXMemberExpression;
"#;

// 1.2 JSX Elements

impl<'a> fmt::Display for JSXIdentifier<'a> {
Expand Down
Loading

0 comments on commit 1145341

Please sign in to comment.