Skip to content

feat(ast/estree)!: option to return JS-only AST#9520

Merged
graphite-app[bot] merged 1 commit intomainfrom
03-03-feat_ast_estree_option_to_return_js-only_ast
Mar 4, 2025
Merged

feat(ast/estree)!: option to return JS-only AST#9520
graphite-app[bot] merged 1 commit intomainfrom
03-03-feat_ast_estree_option_to_return_js-only_ast

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Mar 3, 2025

Add an astType option to parseSync and parseAsync.

When set to 'js', the returned AST does not include TypeScript-related properties. When set to 'ts', it does.

If not specified, the option defaults to same as source type. So when parsing JS / JSX files, the AST returned does not include TS properties by default.

The motivation for allowing the user to override that behavior, is in case someone is parsing a mix of JS and TS files, and want all the ASTs in the same format. In that case they'd set astType: 'ts' for all files.

This is a breaking change as it alters what properties appear in the AST on JS side.

Copy link
Member Author

overlookmotel commented Mar 3, 2025

@github-actions github-actions bot added the A-ast-tools Area - AST tools label Mar 3, 2025
@github-actions github-actions bot added the C-enhancement Category - New feature or request label Mar 3, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 3, 2025

CodSpeed Performance Report

Merging #9520 will create unknown performance changes

Comparing 03-03-feat_ast_estree_option_to_return_js-only_ast (4056560) with main (d55dbe2)

Summary

🆕 33 new benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
🆕 codegen[checker.ts] N/A 23.1 ms N/A
🆕 codegen_sourcemap[checker.ts] N/A 66.2 ms N/A
🆕 isolated-declarations[vue-id.ts] N/A 57.8 ms N/A
🆕 lexer[RadixUIAdoptionSection.jsx] N/A 20.9 µs N/A
🆕 lexer[antd.js] N/A 24.1 ms N/A
🆕 lexer[cal.com.tsx] N/A 5.7 ms N/A
🆕 lexer[checker.ts] N/A 14.5 ms N/A
🆕 lexer[pdf.mjs] N/A 3.8 ms N/A
🆕 linter[RadixUIAdoptionSection.jsx] N/A 2.7 ms N/A
🆕 linter[cal.com.tsx] N/A 1.2 s N/A
🆕 linter[checker.ts] N/A 2.9 s N/A
🆕 mangler[antd.js] N/A 16.1 ms N/A
🆕 mangler[react.development.js] N/A 297.2 µs N/A
🆕 mangler[typescript.js] N/A 39.9 ms N/A
🆕 minifier[antd.js] N/A 163.6 ms N/A
🆕 minifier[react.development.js] N/A 1.8 ms N/A
🆕 minifier[typescript.js] N/A 286.9 ms N/A
🆕 estree[checker.ts] N/A 91.8 ms N/A
🆕 parser[RadixUIAdoptionSection.jsx] N/A 89 µs N/A
🆕 parser[antd.js] N/A 111.9 ms N/A
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

@overlookmotel overlookmotel force-pushed the 03-03-feat_ast_estree_option_to_return_js-only_ast branch from 673323e to fcbec75 Compare March 3, 2025 22:25
@overlookmotel overlookmotel changed the title feat(ast/estree): option to return JS-only AST feat(ast/estree)!: option to return JS-only AST Mar 3, 2025
@overlookmotel overlookmotel marked this pull request as ready for review March 3, 2025 22:33
@overlookmotel overlookmotel force-pushed the 03-03-feat_ast_estree_option_to_return_js-only_ast branch from fcbec75 to 8ba8c68 Compare March 3, 2025 23:05
@overlookmotel overlookmotel force-pushed the 03-03-feat_ast_estree_option_to_return_js-only_ast branch from 8ba8c68 to e477f85 Compare March 4, 2025 12:30
@overlookmotel overlookmotel force-pushed the 03-03-feat_ast_estree_raw_transfer_experimental_ branch from 3e256d7 to 30732cc Compare March 4, 2025 12:30
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Mar 4, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Mar 4, 2025

Merge activity

Add an `astType` option to `parseSync` and `parseAsync`.

When set to `'js'`, the returned AST does not include TypeScript-related properties. When set to `'ts'`, it does.

If not specified, the option defaults to same as source type. So when parsing JS / JSX files, the AST returned does not include TS properties by default.

The motivation for allowing the user to override that behavior, is in case someone is parsing a mix of JS and TS files, and want all the ASTs in the same format. In that case they'd set `astType: 'ts'` for all files.

This is a breaking change as it alters what properties appear in the AST on JS side.
@graphite-app graphite-app bot force-pushed the 03-03-feat_ast_estree_raw_transfer_experimental_ branch from 30732cc to d55dbe2 Compare March 4, 2025 14:40
@graphite-app graphite-app bot force-pushed the 03-03-feat_ast_estree_option_to_return_js-only_ast branch from e477f85 to 4056560 Compare March 4, 2025 14:41
Base automatically changed from 03-03-feat_ast_estree_raw_transfer_experimental_ to main March 4, 2025 14:45
@graphite-app graphite-app bot merged commit 4056560 into main Mar 4, 2025
27 checks passed
@graphite-app graphite-app bot deleted the 03-03-feat_ast_estree_option_to_return_js-only_ast branch March 4, 2025 14:49
@oxc-bot oxc-bot mentioned this pull request Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0-merge Merge with Graphite Merge Queue A-ast Area - AST A-ast-tools Area - AST tools C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant