-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Enable the --define and (global_defs) option to define contents of random variables. #1198
Conversation
So this pr has also support for the squared bracket notation as well. Maybe the documentation should say that javascript style array reference is allowed instead of just saying "oh, you can do this too (but silently don't say what is fine and what is not)". I like the idea for this pr in general though. |
What if the define expression is on the left hand side?
Or if the define expression is referenced indirectly?
|
The compressor has some part of code that test if a node evaluates to a const. Maybe that code can be used to evaluate the expression. Although one can think "Why stop at constants and inject javascript while at it..." |
|
@fabiosantoscode It's good that this PR distinguishes between a local
Could you add such a test to this PR to ensure no future regressions? |
Here's another variation that also works correctly:
That could be added as a test as well. |
- no longer throw errors - guarded by `evaluate` and `unsafe` fixes mishoo#1416 closes mishoo#1198
- no longer throw errors against objects - now depends on `evaluate` - `unsafe` when using objects - support `"a.b":1` on both cli & API - emit warning if variable is modified fixes mishoo#1416 closes mishoo#1198
- no longer throw errors against objects - now depends on `evaluate` - `unsafe` when using objects - support `"a.b":1` on both cli & API - emit warning if variable is modified fixes mishoo#1416 closes mishoo#1198
- no longer throw errors against objects - now depends on `evaluate` - `unsafe` when using objects - support `"a.b":1` on both cli & API - emit warning if variable is modified fixes mishoo#1416 closes mishoo#1198
- support arrays, objects & AST_Node - support `"a.b":1` on both cli & API - emit warning if variable is modified fixes mishoo#1416 closes mishoo#1198
- support arrays, objects & AST_Node - support `"a.b":1` on both cli & API - emit warning if variable is modified - nested definitions override top-level variables fixes mishoo#1416 closes mishoo#1198
- support arrays, objects & AST_Node - support `"a.b":1` on both cli & API - emit warning if variable is modified - override top-level variables fixes mishoo#1416 closes mishoo#1198
- support arrays, objects & AST_Node - support `"a.b":1` on both cli & API - emit warning if variable is modified - override top-level variables fixes mishoo#1416 closes mishoo#1198
- support arrays, objects & AST_Node - support `"a.b":1` on both cli & API - emit warning if variable is modified - override top-level variables fixes mishoo#1416 closes mishoo#1198
- support arrays, objects & AST_Node - support `"a.b":1` on both cli & API - emit warning if variable is modified - override top-level variables fixes mishoo#1416 closes mishoo#1198 closes mishoo#1469
Sometimes your "debug" flag may not be a global variable, it could be a property of a global variable. So I'm sending this PR to allow
--define 'globalVariable.foo.bar=false'
as well as just--define globalVariable=false
.The reasoning behind building this was to support React and common React code which uses
if (process.env.NODE_ENV !== "production")
guards all the time for development-only code. I found some inspiration in webpack's DefinePlugin for the interface, and started implementing.