Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only check extensiblity of props
Also run preventExtensions on it after modifications
  • Loading branch information
EmmaSimon committed Mar 20, 2018
commit ee403bd71bd2a0d061db635d1a5f0c75a1641506
17 changes: 9 additions & 8 deletions src/linkClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,19 @@ const linkArray = (array: Array, styles: Object, configuration: Object) => {

const linkElement = (element: ReactElement, styles: Object, configuration: Object): ReactElement => {
let appendClassName;
let elementIsFrozen;
let elementShallowCopy;

elementShallowCopy = element;
elementIsFrozen = Object.isFrozen && (
Object.isFrozen(elementShallowCopy) ||
Object.isFrozen(elementShallowCopy.props)
) || Object.isExtensible && (
!Object.isExtensible(elementShallowCopy) ||
!Object.isExtensible(elementShallowCopy.props)
);

const elementIsFrozen = Object.isFrozen && Object.isFrozen(elementShallowCopy);
const propsNotExtensible = Object.isExtensible && !Object.isExtensible(elementShallowCopy.props);

if (elementIsFrozen) {
// https://github.com/facebook/react/blob/v0.13.3/src/classic/element/ReactElement.js#L131
elementShallowCopy = objectUnfreeze(elementShallowCopy);
elementShallowCopy.props = objectUnfreeze(elementShallowCopy.props);
} else if (propsNotExtensible) {
elementShallowCopy.props = objectUnfreeze(elementShallowCopy.props);
}

const styleNames = parseStyleName(elementShallowCopy.props.styleName || '', configuration.allowMultiple);
Expand Down Expand Up @@ -83,6 +80,10 @@ const linkElement = (element: ReactElement, styles: Object, configuration: Objec
Object.freeze(elementShallowCopy);
}

if (propsNotExtensible) {
Object.preventExtensions(elementShallowCopy.props);
}

return elementShallowCopy;
};

Expand Down