-
Notifications
You must be signed in to change notification settings - Fork 127
feat(rspeedy): express SWC baseline via env instead of jsc.target #2748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bb73026
feat(rspeedy): express SWC baseline via env instead of jsc.target
upupming 73b2e32
test(rspeedy): isolate NODE_ENV between swc-config tests
upupming af28e1e
refactor(rspeedy): trim swc env refactor per review
upupming 53d2d32
test(rspeedy): keep swc-config layer test diff minimal
upupming 4dd74d6
Merge branch 'main' into feat/swc-target-to-env
upupming 09783b9
fix(genui): order a2ui-catalog-extractor build before a2ui api-extractor
upupming 4dd58b8
Merge branch 'main' into feat/swc-target-to-env
upupming 2b215e3
refactor(rspeedy): main thread keeps fixed es2019 env baseline
upupming c98fa8e
test(rspeedy): guard env.include stays equivalent to jsc.target
upupming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| "@lynx-js/rspeedy": minor | ||
| "@lynx-js/react-rsbuild-plugin": minor | ||
| --- | ||
|
|
||
| Express the SWC compilation baseline through `env` (a high `targets` plus an explicit `include` transform list) instead of `jsc.target`. The emitted build output is unchanged for existing projects. | ||
|
|
||
| Because `env` and `jsc.target` are mutually exclusive in SWC, `tools.swc.jsc.target` is no longer accepted and now throws a clear error. To downlevel specific syntax, add the corresponding transforms to `tools.swc.env.include` instead — they extend the base/background baseline (the main thread keeps its fixed es2019 baseline, matching the previous `jsc.target` behavior). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/rspeedy/core/test/utils/getESVersionEnvInclude.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright 2024 The Lynx Authors. All rights reserved. | ||
| // Licensed under the Apache License Version 2.0 that can be found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
| import { transformSync } from '@swc/core' | ||
| import { describe, expect, test } from 'vitest' | ||
|
|
||
| import { | ||
| ES_ENV_TARGETS, | ||
| getESVersionEnvInclude, | ||
| } from '../../src/utils/getESVersionTarget.js' | ||
|
|
||
| // Syntax spanning ES2016 through ES2025+ (the regex `v` flag, regex modifiers | ||
| // and duplicate named capture groups are the newest entries). The guard below | ||
| // compiles this with `jsc.target` (SWC's canonical lowering for an ES version) | ||
| // and with our `env` config, then asserts byte-identical output. | ||
| // | ||
| // If a future SWC upgrade starts lowering some syntax at the target that our | ||
| // explicit `include` list omits — or stops needing one we list — the two | ||
| // outputs diverge and this test fails, flagging that `getESVersionEnvInclude` | ||
| // drifted from `jsc.target` and must be updated. Extend this fixture whenever | ||
| // SWC gains support for newer syntax so the guard keeps covering it. | ||
| const MODERN_SYNTAX = [ | ||
| 'export * as ns from "mod";', | ||
| 'const oc = a?.b?.c;', | ||
| 'const nc = a ?? b;', | ||
| 'let x = 0; x ||= 1; x &&= 2; x ??= 3;', | ||
| 'const num = 1_000_000;', | ||
| 'async function af() { return await g(); }', | ||
| 'async function* ag() { yield 1; }', | ||
| 'const spread = { ...a, b: 1 };', | ||
| 'const dotall = /a.b/s;', | ||
| 'const named = /(?<year>\\d{4})/;', | ||
| 'const exp = 2 ** 10;', | ||
| 'try { foo() } catch { bar() }', | ||
| 'class C { #priv = 1; static sb = 2; static { this.x = 1 } #m() {} }', | ||
| 'const vFlag = /[\\p{ASCII}]/v;', | ||
| 'const modifiers = /(?i:abc)/;', | ||
| 'const dupNamed = /(?<a>x)|(?<a>y)/;', | ||
| ].join('\n') | ||
|
|
||
| function viaTarget(target: 'es2015' | 'es2019'): string { | ||
| return transformSync(MODERN_SYNTAX, { | ||
| isModule: true, | ||
| jsc: { parser: { syntax: 'ecmascript' }, target }, | ||
| }).code | ||
| } | ||
|
|
||
| function viaEnv(target: 'es2015' | 'es2019'): string { | ||
| return transformSync(MODERN_SYNTAX, { | ||
| isModule: true, | ||
| jsc: { parser: { syntax: 'ecmascript' } }, | ||
| env: { targets: ES_ENV_TARGETS, include: getESVersionEnvInclude(target) }, | ||
| }).code | ||
| } | ||
|
|
||
| describe('getESVersionEnvInclude', () => { | ||
| // Uses `@swc/core` as a stand-in for rspack's builtin SWC: the | ||
| // `env.include` <-> `jsc.target` equivalence is a preset-env property | ||
| // shared by both. | ||
| test.each(['es2015', 'es2019'] as const)( | ||
| 'env.include reproduces `jsc.target: %s` exactly', | ||
| (target) => { | ||
| expect(viaEnv(target)).toBe(viaTarget(target)) | ||
| }, | ||
| ) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.