-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add @__KEY__ annotation to mangle string literals (#1365)
* Add @__KEY__ annotation Adding a @__KEY__ annotation before a string literal will now cause it to be mangled like a property name during the mangle_props phase. * Never double mangle _KEY string literals * Add tests for _KEY annotation * Add _KEY annotation to readme
- Loading branch information
Showing
6 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,83 @@ | ||
key_annotation_negative_case: { | ||
options = { | ||
defaults: false, | ||
inline: false, | ||
}; | ||
mangle = { | ||
properties: true, | ||
}; | ||
input: { | ||
function lookup(object, key) { | ||
return object[key]; | ||
} | ||
lookup({ someprop: "bar" }, "someprop"); | ||
} | ||
expect: { | ||
function lookup(o, p) { | ||
return o[p]; | ||
} | ||
lookup({ o: "bar" }, "someprop"); | ||
} | ||
} | ||
|
||
key_annotation_basic_use: { | ||
options = { | ||
defaults: false, | ||
inline: false, | ||
}; | ||
mangle = { | ||
properties: true, | ||
}; | ||
input: { | ||
function lookup(object, key) { | ||
return object[key]; | ||
} | ||
lookup({ someprop: "bar" }, /*@__KEY__*/ "someprop"); | ||
} | ||
expect: { | ||
function lookup(o,p){ | ||
return o[p] | ||
} | ||
lookup({o:"bar"},"o"); | ||
} | ||
} | ||
|
||
key_annotation_in_operator: { | ||
options = { | ||
defaults: false, | ||
inline: false, | ||
}; | ||
mangle = { | ||
properties: true, | ||
}; | ||
input: { | ||
const object = { someprop: "bar", o: true} | ||
"someprop" in object; | ||
/*@__KEY__*/ "someprop" in object; | ||
} | ||
expect: { | ||
const object={o:"bar", p : true}; | ||
"o"in object; | ||
"o"in object; | ||
} | ||
} | ||
key_annotation_in_operator_tricky_case: { | ||
options = { | ||
defaults: false, | ||
inline: false, | ||
}; | ||
mangle = { | ||
properties: true, | ||
}; | ||
input: { | ||
// By default someprop mangles to "o", add key "o" to try and trip up the mangler | ||
const object = { someprop: "bar", o: true} | ||
"someprop" in object; | ||
/*@__KEY__*/ "someprop" in object; | ||
} | ||
expect: { | ||
const object={o:"bar", p: true}; | ||
"o"in object; | ||
"o"in object; | ||
} | ||
} |