Skip to content
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

[BUGFIX lts] Fix transpilation issues (e.g. _createSuper is not a function) when used with Babel 7.9.0+. #18831

Merged
merged 2 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
"test:browserstack": "node bin/run-browserstack-tests.js"
},
"dependencies": {
"@babel/helper-module-imports": "^7.0.0",
"@babel/plugin-transform-block-scoping": "^7.6.2",
"@babel/plugin-transform-object-assign": "^7.2.0",
"@babel/helper-module-imports": "^7.8.3",
"@babel/plugin-transform-block-scoping": "^7.8.3",
"@babel/plugin-transform-object-assign": "^7.8.3",
"@ember/edition-utils": "^1.2.0",
"babel-plugin-debug-macros": "^0.3.3",
"babel-plugin-filter-imports": "^4.0.0",
Expand All @@ -58,7 +58,7 @@
"broccoli-funnel": "^2.0.2",
"broccoli-merge-trees": "^3.0.2",
"chalk": "^3.0.0",
"ember-cli-babel": "^7.13.2",
"ember-cli-babel": "^7.18.0",
"ember-cli-get-component-path-option": "^1.0.0",
"ember-cli-is-package-missing": "^1.0.0",
"ember-cli-normalize-entity-name": "^1.0.0",
Expand All @@ -73,7 +73,7 @@
"silent-error": "^1.1.1"
},
"devDependencies": {
"@babel/preset-env": "^7.7.7",
"@babel/preset-env": "^7.9.0",
"@glimmer/compiler": "^0.48.0",
"@glimmer/env": "^0.1.7",
"@glimmer/interfaces": "^0.48.0",
Expand All @@ -89,11 +89,11 @@
"@typescript-eslint/parser": "^2.15.0",
"auto-dist-tag": "^1.0.0",
"aws-sdk": "^2.573.0",
"babel-eslint": "^10.0.3",
"babel-eslint": "^10.1.0",
"babel-plugin-module-resolver": "^4.0.0",
"babel-template": "^6.26.0",
"backburner.js": "^2.6.0",
"broccoli-babel-transpiler": "^7.3.0",
"broccoli-babel-transpiler": "^7.4.0",
"broccoli-file-creator": "^2.1.1",
"broccoli-persistent-filter": "^2.3.1",
"broccoli-plugin": "^3.0.0",
Expand Down
76 changes: 76 additions & 0 deletions packages/external-helpers/lib/external-helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/* globals Reflect */

import { DEBUG } from '@glimmer/env';

const setPrototypeOf = Object.setPrototypeOf;
const getPrototypeOf = Object.getPrototypeOf;

const hasReflectConstruct = typeof Reflect === 'object' && typeof Reflect.construct === 'function';

const nativeWrapperCache = new Map();

Expand Down Expand Up @@ -117,3 +122,74 @@ export function objectDestructuringEmpty(obj) {
throw new TypeError('Cannot destructure undefined');
}
}

/*
Differs from default implementation by checking for _any_ `Reflect.construct`
(the default implementation tries to ensure that `Reflect.construct` is truly
the native one).

Original source: https://github.com/babel/babel/blob/v7.9.2/packages/babel-helpers/src/helpers.js#L738-L757
*/
export function createSuper(Derived) {
return function() {
let Super = getPrototypeOf(Derived);
let result;

if (hasReflectConstruct) {
// NOTE: This doesn't work if this.__proto__.constructor has been modified.
let NewTarget = getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}

return possibleConstructorReturn(this, result);
};
}

/*
Does not differ from default implementation.
*/
function arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;

let arr2 = new Array(len);
for (let i = 0; i < len; i++) {
arr2[i] = arr[i];
}

return arr2;
}

/*
Does not differ from default implementation.
*/
function unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === 'string') return arrayLikeToArray(o, minLen);
let n = Object.prototype.toString.call(o).slice(8, -1);
if (n === 'Object' && o.constructor) n = o.constructor.name;
if (n === 'Map' || n === 'Set') return Array.from(n);
if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
return arrayLikeToArray(o, minLen);
}

/*
Does not differ from default implementation.
*/
export function createForOfIteratorHelperLoose(o) {
let i = 0;
if (typeof Symbol === 'undefined' || o[Symbol.iterator] == null) {
// Fallback for engines without symbol support
if (Array.isArray(o) || (o = unsupportedIterableToArray(o)))
return function() {
if (i >= o.length) return { done: true };
return { done: false, value: o[i++] };
};
throw new TypeError(
'Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
);
}
i = o[Symbol.iterator]();
return i.next.bind(i);
}
Loading