-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Access global.* using array notation #1144
Conversation
this.foo.bar.baz = (function () { | ||
this['foo'] = this['foo'] || {}; | ||
this['foo']['bar'] = this['foo']['bar'] || {}; | ||
this['foo']['bar']['baz'] = (function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still processes namespaced exports by splitting on the dots
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global['module-name-with-dashes'] = global['module-name-with-dashes'] || {}))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allow dashes
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global['@scoped/npm-package'] = global['@scoped/npm-package'] || {}))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allow arbitrary strings, including npm scoped packages. Not sure this is/should be a requirement, but I added a test anyway because of #582
Thanks @christopherthielen! Any chance you could modify this PR such that valid property names are left as-is? There are advantages to using dot notation, so I think it would be better if properties were only quoted as necessary since they're in the minority. |
sure, no problem |
This allows arbitrary `moduleName` (including names with dashes like `ui-router` or scoped npm packages like `@angular/core`) to be added to the global object. Closes rollup#582 Closes rollup#584
a964047
to
caae8b6
Compare
caae8b6
to
bb546d3
Compare
Okey dokey, done. I chose to be naive about when to quote/not quote properties. The actual rules for javascript property access are more complex: https://mathiasbynens.be/notes/javascript-identifiers . There are npm modules you could use to test if a property can be accessed using a dot or not, but it seemed overkill. This should catch 99% and quote when unsure. Also I didn't want to force maintenance of a variable checker on the project. I did find some (low-stars) npm packages that could be used if you prefer something along those lines. |
Excellent, thank you! |
Allow arbitrary
moduleName
(including names with dashes likeui-router
or scoped npm packages like@angular/core
) to be added to the global object.Closes #582
Closes #584