Skip to content

Use an emit helper (or Object.assign) for JsxSpreadAttributes - #7952

Merged
Daniel Rosenwasser (DanielRosenwasser) merged 6 commits into
masterfrom
objectAssignPoly
Apr 8, 2016
Merged

Daniel Rosenwasser (DanielRosenwasser) merged 6 commits into
masterfrom
objectAssignPoly

Conversation

@DanielRosenwasser

Copy link
Copy Markdown
Member

This PR introduces an __assign helper that we can leverage for React emit, as well as object spread properties down the road (with some tweaking).

Fixes #7270.

Ron Buckton (@rbuckton) Ryan Cavanaugh (@RyanCavanaugh) Mohamed Hegazy (@mhegazy)

Comment thread src/compiler/emitter.ts Outdated
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var i = 1, n = arguments.length; i < n; i++) {
var s = arguments[i];
if (s != null) for (var p in s) if (s.hasOwnProperty(p)) t[p] = s[p];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null test is unnecessary

@DanielRosenwasser

Copy link
Copy Markdown
Member Author

Thanks for the reactions Basarat Ali Syed (@basarat) 😄 🌹

Comment thread src/compiler/emitter.ts
};`;

const assignHelper = `
var __assign = (this && this.__assign) || Object.assign || function(t) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polyfill I found (and what React used) convert t into an object, like:

if (t == null) {
throw new TypeError('Object.assign cannot be called with null or undefined');
}
var result = Object(t);

I'm unsure if this is necessary with current browsers. But https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill does to.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For our uses this should it should be unnecessary anyway.

@RyanCavanaugh

Copy link
Copy Markdown
Member

👍 && thank you dan (@gaearon)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

5 participants