-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(es/typescript): Handle TypeScript expressions in enum transformation #11769
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
Open
magic-akari
wants to merge
15
commits into
swc-project:main
Choose a base branch
from
magic-akari:fix/issue-11761
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
af91f1a
fix(es/typescript): Handle TypeScript expressions in enum transformation
magic-akari c9ea557
chore: update test cases
magic-akari 891439e
refactor(es/typescript): simplify enum value computation and transfor…
magic-akari 96965d9
chore: update test cases
magic-akari 6433532
chore: update test cases
magic-akari fd25b41
fix(typescript): Handle enum member references correctly
magic-akari d3b6400
chore: update test cases
magic-akari fd53909
fix: clippy issue
magic-akari 977d1f7
fix(es/typescript): handle enum member names in resolver
magic-akari fa963a6
chore: update test cases
magic-akari d2c98c1
fix: apply copilot suggestions
magic-akari 9303595
fix: apply copilot suggestions
magic-akari 3d75291
fix: apply copilot suggestions
magic-akari 1062344
fix(es/typescript): correct enum inline
magic-akari 00d0558
fix
magic-akari 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
Some comments aren't visible on the classic Files Changed page.
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
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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| //// [constEnum2.ts] | ||
| var D, D1 = ((D = D1 || {})[D.e = 199 * Math.floor(1000 * Math.random())] = "e", D[D.f = 10 - 100 * Math.floor(Math.random() % 8)] = "f", D[D.g = 0] = "g", D); | ||
| var D, D1 = ((D = D1 || {})[D.e = 199 * Math.floor(1000 * Math.random())] = "e", D[D.f = D.d - 100 * Math.floor(Math.random() % 8)] = "f", D[D.g = 0] = "g", D); | ||
magic-akari marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ use crate::{ | |
| retain::{should_retain_module_item, should_retain_stmt}, | ||
| semantic::SemanticInfo, | ||
| shared::enum_member_id_atom, | ||
| ts_enum::{TsEnumRecordKey, TsEnumRecordValue}, | ||
| ts_enum::{EnumValueComputer, TsEnumRecordKey, TsEnumRecordValue}, | ||
| utils::{assign_value_to_this_private_prop, assign_value_to_this_prop, Factory}, | ||
| }; | ||
|
|
||
|
|
@@ -1063,7 +1063,16 @@ impl Transform { | |
| member_name: name.clone(), | ||
| }; | ||
|
|
||
| let value = self.semantic.enum_record.get(&key).unwrap().clone(); | ||
| let mut value = self.semantic.enum_record.get(&key).unwrap().clone(); | ||
|
|
||
| if let TsEnumRecordValue::Opaque(expr) = &mut value { | ||
| *expr = m.init.unwrap(); | ||
| expr.visit_mut_with(&mut EnumValueComputer { | ||
| enum_id: &id.to_id(), | ||
| unresolved_ctxt: self.unresolved_ctxt, | ||
| record: &self.semantic.enum_record, | ||
| }); | ||
magic-akari marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Comment on lines
+1088
to
+1095
|
||
| } | ||
|
|
||
| EnumMemberItem { span, name, value } | ||
| }) | ||
|
|
||
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
2 changes: 1 addition & 1 deletion
2
crates/swc_ecma_transforms_typescript/tests/__swc_snapshots__/tests/strip.rs/issue_6219.js
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| var A = function(A) { | ||
| A[A["a"] = a] = "a"; | ||
| A[A["a"] = A.a] = "a"; | ||
| return A; | ||
| }(A || {}); |
8 changes: 8 additions & 0 deletions
8
...transforms_typescript/tests/__swc_snapshots__/tests/strip.rs/ts_enum_with_nested_class.js
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 @@ | ||
| var Foo = function(Foo) { | ||
| Foo[Foo["a"] = (class { | ||
| constructor(b){ | ||
| this.b = b; | ||
| } | ||
| }, 0)] = "a"; | ||
| return Foo; | ||
| }(Foo || {}); |
11 changes: 11 additions & 0 deletions
11
..._transforms_typescript/tests/__swc_snapshots__/tests/strip.rs/ts_enum_with_nested_enum.js
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,11 @@ | ||
| var Foo = function(Foo) { | ||
| Foo[Foo["a"] = (()=>{ | ||
| let Bar = /*#__PURE__*/ function(Bar) { | ||
| Bar["a"] = "a"; | ||
| Bar["b"] = "b"; | ||
| return Bar; | ||
| }({}); | ||
| return 0; | ||
| })()] = "a"; | ||
| return Foo; | ||
| }(Foo || {}); |
4 changes: 4 additions & 0 deletions
4
..._transforms_typescript/tests/__swc_snapshots__/tests/strip.rs/ts_enum_with_opaque_expr.js
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,4 @@ | ||
| var Foo = function(Foo) { | ||
| Foo[Foo["a"] = foo('x')] = "a"; | ||
| return Foo; | ||
| }(Foo || {}); |
5 changes: 5 additions & 0 deletions
5
...ansforms_typescript/tests/__swc_snapshots__/tests/strip.rs/ts_enum_with_type_assertion.js
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,5 @@ | ||
| var RefType = /*#__PURE__*/ function(RefType) { | ||
| RefType["property"] = "11"; | ||
| RefType["event"] = "22"; | ||
| return RefType; | ||
| }(RefType || {}); |
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
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.