Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 25.2k
Make the packager work with babel strict mode transform#5422
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,30 @@ | ||
| /* eslint global-strict: 0 */ | ||
| (function(GLOBAL) { | ||
| /** | ||
| * The document must be shimmed before anything else that might define the | ||
| * `ExecutionEnvironment` module (which checks for `document.createElement`). | ||
| */ | ||
| /* eslint strict: 0 */ | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
| ||
| // The browser defines Text and Image globals by default. If you forget to | ||
| // require them, then the error message is very confusing. | ||
| function getInvalidGlobalUseError(name) { | ||
| return new Error( | ||
| 'You are trying to render the global ' + name + ' variable as a ' + | ||
| 'React element. You probably forgot to require ' + name + '.' | ||
| ); | ||
| // TODO: Remove document polyfill now that chrome debugging is in a web worker. | ||
| // The browser defines Text and Image globals by default. If you forget to | ||
| // require them, then the error message is very confusing. | ||
| function getInvalidGlobalUseError(name) { | ||
| return new Error( | ||
| 'You are trying to render the global ' + name + ' variable as a ' + | ||
| 'React element. You probably forgot to require ' + name + '.' | ||
| ); | ||
| } | ||
| global.Text = { | ||
| get defaultProps() { | ||
| throw getInvalidGlobalUseError('Text'); | ||
| } | ||
| GLOBAL.Text = { | ||
| get defaultProps() { | ||
| throw getInvalidGlobalUseError('Text'); | ||
| } | ||
| }; | ||
| GLOBAL.Image = { | ||
| get defaultProps() { | ||
| throw getInvalidGlobalUseError('Image'); | ||
| } | ||
| }; | ||
| // Force `ExecutionEnvironment.canUseDOM` to be false. | ||
| if (GLOBAL.document) { | ||
| GLOBAL.document.createElement = null; | ||
| }; | ||
| global.Image = { | ||
| get defaultProps() { | ||
| throw getInvalidGlobalUseError('Image'); | ||
| } | ||
| }; | ||
| // Force `ExecutionEnvironment.canUseDOM` to be false. | ||
| if (global.document) { | ||
| global.document.createElement = null; | ||
| } | ||
| // There is no DOM so MutationObserver doesn't make sense. It is used | ||
| // as feature detection in Bluebird Promise implementation | ||
| GLOBAL.MutationObserver = undefined; | ||
| })(this); | ||
| // There is no DOM so MutationObserver doesn't make sense. It is used | ||
| // as feature detection in Bluebird Promise implementation | ||
| global.MutationObserver = undefined; | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here? | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -58,6 +58,14 @@ describe('Resolver', function() { | ||
| return module; | ||
| } | ||
| function createPolyfill(id, dependencies) { | ||
| var polyfill = new Polyfill({}); | ||
| polyfill.getName.mockImpl(() => Promise.resolve(id)); | ||
| polyfill.getDependencies.mockImpl(() => Promise.resolve(dependencies)); | ||
| polyfill.isPolyfill.mockReturnValue(true); | ||
| return polyfill; | ||
| } | ||
| describe('getDependencies', function() { | ||
| pit('should get dependencies with polyfills', function() { | ||
| var module = createModule('index'); | ||
| @@ -1020,5 +1028,26 @@ describe('Resolver', function() { | ||
| ].join('\n')); | ||
| }); | ||
| }); | ||
| pit('should resolve polyfills', function () { | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for adding tests | ||
| const depResolver = new Resolver({ | ||
| projectRoot: '/root', | ||
| }); | ||
| const polyfill = createPolyfill('test polyfill', []); | ||
| const code = [ | ||
| 'global.fetch = () => 1;', | ||
| ].join(''); | ||
| return depResolver.wrapModule( | ||
| null, | ||
| polyfill, | ||
| code | ||
| ).then(processedCode => { | ||
| expect(processedCode.code).toEqual([ | ||
| '(function(global) {', | ||
| 'global.fetch = () => 1;', | ||
| "\n})(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this);", | ||
| ].join('')); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,54 +5,51 @@ | ||
| * @polyfill | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Files with Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don’t read that annotation anywhere. We just add all polyfills as special cases Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i.e. it should be fine given the changes in Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see. Does that mean you are against this specific change? | ||
| */ | ||
| /*eslint-disable */ | ||
| /*jslint bitwise: true */ | ||
| /* eslint-disable */ | ||
| (function(undefined) { | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | ||
| function findIndex(predicate, context) { | ||
| if (this == null) { | ||
| throw new TypeError( | ||
| 'Array.prototype.findIndex called on null or undefined' | ||
| ); | ||
| } | ||
| if (typeof predicate !== 'function') { | ||
| throw new TypeError('predicate must be a function'); | ||
| } | ||
| var list = Object(this); | ||
| var length = list.length >>> 0; | ||
| for (var i = 0; i < length; i++) { | ||
| if (predicate.call(context, list[i], i, list)) { | ||
| return i; | ||
| } | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | ||
| function findIndex(predicate, context) { | ||
| if (this == null) { | ||
| throw new TypeError( | ||
| 'Array.prototype.findIndex called on null or undefined' | ||
| ); | ||
| } | ||
| if (typeof predicate !== 'function') { | ||
| throw new TypeError('predicate must be a function'); | ||
| } | ||
| var list = Object(this); | ||
| var length = list.length >>> 0; | ||
| for (var i = 0; i < length; i++) { | ||
| if (predicate.call(context, list[i], i, list)) { | ||
| return i; | ||
| } | ||
| return -1; | ||
| } | ||
| return -1; | ||
| } | ||
| if (!Array.prototype.findIndex) { | ||
| Object.defineProperty(Array.prototype, 'findIndex', { | ||
| enumerable: false, | ||
| writable: true, | ||
| configurable: true, | ||
| value: findIndex | ||
| }); | ||
| } | ||
| if (!Array.prototype.findIndex) { | ||
| Object.defineProperty(Array.prototype, 'findIndex', { | ||
| enumerable: false, | ||
| writable: true, | ||
| configurable: true, | ||
| value: findIndex | ||
| }); | ||
| } | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find | ||
| if (!Array.prototype.find) { | ||
| Object.defineProperty(Array.prototype, 'find', { | ||
| enumerable: false, | ||
| writable: true, | ||
| configurable: true, | ||
| value: function(predicate, context) { | ||
| if (this == null) { | ||
| throw new TypeError( | ||
| 'Array.prototype.find called on null or undefined' | ||
| ); | ||
| } | ||
| var index = findIndex.call(this, predicate, context); | ||
| return index === -1 ? undefined : this[index]; | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find | ||
| if (!Array.prototype.find) { | ||
| Object.defineProperty(Array.prototype, 'find', { | ||
| enumerable: false, | ||
| writable: true, | ||
| configurable: true, | ||
| value: function(predicate, context) { | ||
| if (this == null) { | ||
| throw new TypeError( | ||
| 'Array.prototype.find called on null or undefined' | ||
| ); | ||
| } | ||
| }); | ||
| } | ||
| })(); | ||
| var index = findIndex.call(this, predicate, context); | ||
| return index === -1 ? undefined : this[index]; | ||
| } | ||
| }); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Should we get rid of the
GLOBALglobal variable and just use the node standardglobaleverywhere? Except for this file it is used in 1 or 2 other places in the codebase.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.
GLOBALis valid in Node so removing it will probably break some third party npm modules.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.
Ok let's leave it like this.