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

Added runtime TypeError for non-function, non-null __extends #37283

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
124 changes: 63 additions & 61 deletions src/compiler/transformers/es2015.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ namespace ts {
}

const enum Jump {
Break = 1 << 1,
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
Continue = 1 << 2,
Return = 1 << 3
Break = 1 << 1,
Continue = 1 << 2,
Return = 1 << 3
}

interface ConvertedLoopState {
Expand Down Expand Up @@ -1597,7 +1597,7 @@ namespace ts {
if (!isPrivateIdentifier(propertyName) && context.getCompilerOptions().useDefineForClassFields) {
const name = isComputedPropertyName(propertyName) ? propertyName.expression
: isIdentifier(propertyName) ? createStringLiteral(unescapeLeadingUnderscores(propertyName.escapedText))
: propertyName;
: propertyName;
e = createObjectDefinePropertyCall(receiver, name, createPropertyDescriptor({ value: memberFunction, enumerable: false, writable: true, configurable: true }));
}
else {
Expand Down Expand Up @@ -2418,28 +2418,28 @@ namespace ts {
const forStatement = setTextRange(
createFor(
/*initializer*/ setEmitFlags(
setTextRange(
createVariableDeclarationList([
setTextRange(createVariableDeclaration(counter, /*type*/ undefined, createLiteral(0)), moveRangePos(node.expression, -1)),
setTextRange(createVariableDeclaration(rhsReference, /*type*/ undefined, expression), node.expression)
]),
node.expression
),
EmitFlags.NoHoisting
setTextRange(
createVariableDeclarationList([
setTextRange(createVariableDeclaration(counter, /*type*/ undefined, createLiteral(0)), moveRangePos(node.expression, -1)),
setTextRange(createVariableDeclaration(rhsReference, /*type*/ undefined, expression), node.expression)
]),
node.expression
),
EmitFlags.NoHoisting
),
/*condition*/ setTextRange(
createLessThan(
counter,
createPropertyAccess(rhsReference, "length")
),
node.expression
createLessThan(
counter,
createPropertyAccess(rhsReference, "length")
),
node.expression
),
/*incrementor*/ setTextRange(createPostfixIncrement(counter), node.expression),
/*statement*/ convertForOfStatementHead(
node,
createElementAccess(rhsReference, counter),
convertedLoopBodyStatements
)
node,
createElementAccess(rhsReference, counter),
convertedLoopBodyStatements
)
),
/*location*/ node
);
Expand Down Expand Up @@ -2472,22 +2472,22 @@ namespace ts {
setTextRange(
createFor(
/*initializer*/ setEmitFlags(
setTextRange(
createVariableDeclarationList([
setTextRange(createVariableDeclaration(iterator, /*type*/ undefined, initializer), node.expression),
createVariableDeclaration(result, /*type*/ undefined, next)
]),
node.expression
),
EmitFlags.NoHoisting
setTextRange(
createVariableDeclarationList([
setTextRange(createVariableDeclaration(iterator, /*type*/ undefined, initializer), node.expression),
createVariableDeclaration(result, /*type*/ undefined, next)
]),
node.expression
),
EmitFlags.NoHoisting
),
/*condition*/ createLogicalNot(createPropertyAccess(result, "done")),
/*incrementor*/ createAssignment(result, next),
/*statement*/ convertForOfStatementHead(
node,
createPropertyAccess(result, "value"),
convertedLoopBodyStatements
)
node,
createPropertyAccess(result, "value"),
convertedLoopBodyStatements
)
),
/*location*/ node
),
Expand Down Expand Up @@ -2520,42 +2520,42 @@ namespace ts {
createBlock([
createTry(
/*tryBlock*/ createBlock([
setEmitFlags(
createIf(
setEmitFlags(
createIf(
createLogicalAnd(
createLogicalAnd(
createLogicalAnd(
result,
createLogicalNot(
createPropertyAccess(result, "done")
)
),
createAssignment(
returnMethod,
createPropertyAccess(iterator, "return")
result,
createLogicalNot(
createPropertyAccess(result, "done")
)
),
createExpressionStatement(
createFunctionCall(returnMethod, iterator, [])
createAssignment(
returnMethod,
createPropertyAccess(iterator, "return")
)
),
EmitFlags.SingleLine
createExpressionStatement(
createFunctionCall(returnMethod, iterator, [])
)
),
]),
EmitFlags.SingleLine
),
]),
/*catchClause*/ undefined,
/*finallyBlock*/ setEmitFlags(
createBlock([
setEmitFlags(
createIf(
errorRecord,
createThrow(
createPropertyAccess(errorRecord, "error")
)
),
EmitFlags.SingleLine
)
]),
EmitFlags.SingleLine
)
createBlock([
setEmitFlags(
createIf(
errorRecord,
createThrow(
createPropertyAccess(errorRecord, "error")
)
),
EmitFlags.SingleLine
)
]),
EmitFlags.SingleLine
)
)
])
);
Expand Down Expand Up @@ -4321,6 +4321,8 @@ namespace ts {
};

return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/abstractClassInLocalScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/abstractProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/abstractPropertyInConstructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/abstractPropertyNegative.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/accessOverriddenBaseClassMember1.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/accessorsOverrideProperty7.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/aliasUsageInAccessorsOfClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/aliasUsageInArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/aliasUsageInFunctionExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/aliasUsageInGenericFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/aliasUsageInIndexerOfClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/aliasUsageInObjectLiteral.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/aliasUsageInOrExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand All @@ -70,6 +72,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/aliasUsageInVarAssignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/ambiguousOverloadResolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/amdDeclarationEmitNoExtraDeclare.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var __extends = (this && this.__extends) || (function () {
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + b + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
Expand Down
Loading