Skip to content
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
12 changes: 9 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46774,6 +46774,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function checkInterfaceDeclaration(node: InterfaceDeclaration) {
// Grammar checking
if (!checkGrammarModifiers(node)) checkGrammarInterfaceDeclaration(node);
if (!allowBlockDeclarations(node.parent)) {
grammarErrorOnNode(node, Diagnostics._0_declarations_can_only_be_declared_inside_a_block, "interface");
}

checkTypeParameters(node.typeParameters);
addLazyDiagnostic(() => {
Expand Down Expand Up @@ -46817,6 +46820,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// Grammar checking
checkGrammarModifiers(node);
checkTypeNameIsReserved(node.name, Diagnostics.Type_alias_name_cannot_be_0);
if (!allowBlockDeclarations(node.parent)) {
grammarErrorOnNode(node, Diagnostics._0_declarations_can_only_be_declared_inside_a_block, "type");
}
checkExportsOnMergedDeclarations(node);
checkTypeParameters(node.typeParameters);
if (node.type.kind === SyntaxKind.IntrinsicKeyword) {
Expand Down Expand Up @@ -52051,7 +52057,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return false;
}

function allowLetAndConstDeclarations(parent: Node): boolean {
function allowBlockDeclarations(parent: Node): boolean {
switch (parent.kind) {
case SyntaxKind.IfStatement:
case SyntaxKind.DoStatement:
Expand All @@ -52062,14 +52068,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
case SyntaxKind.ForOfStatement:
return false;
case SyntaxKind.LabeledStatement:
return allowLetAndConstDeclarations(parent.parent);
return allowBlockDeclarations(parent.parent);
}

return true;
}

function checkGrammarForDisallowedBlockScopedVariableStatement(node: VariableStatement) {
if (!allowLetAndConstDeclarations(node.parent)) {
if (!allowBlockDeclarations(node.parent)) {
const blockScopeKind = getCombinedNodeFlagsCached(node.declarationList) & NodeFlags.BlockScoped;
if (blockScopeKind) {
const keyword = blockScopeKind === NodeFlags.Let ? "let" :
Expand Down
24 changes: 17 additions & 7 deletions src/compiler/factory/emitHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1188,13 +1188,23 @@ const importStarHelper: UnscopedEmitHelper = {
dependencies: [createBindingHelper, setModuleDefaultHelper],
priority: 2,
text: `
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};`,
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();`,
};

// emit helper for `import Name from "foo"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2784,11 +2784,11 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations_9009" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9009" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[At least one accessor must have an explicit return type annotation with --isolatedDeclarations.]]></Val>
<Val><![CDATA[At least one accessor must have an explicit type annotation with --isolatedDeclarations.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[至少一个访问器必须具有带有 --isolatedDeclarations 的显式返回类型注释。]]></Val>
<Val><![CDATA[至少一个访问器必须具有带有 --isolatedDeclarations 的显式类型注释。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
Expand Down Expand Up @@ -5040,11 +5040,11 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_su_9025" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_its_type_This_is_not_sup_9025" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations.]]></Val>
<Val><![CDATA[Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[为此参数发出的声明要求隐式添加未定义的类型。--isolatedDeclarations 不支持此功能。]]></Val>
<Val><![CDATA[为此参数发出的声明要求将未定义隐式添加到其类型。--isolatedDeclarations 不支持此功能。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
Expand Down Expand Up @@ -11548,7 +11548,7 @@
<Str Cat="Text">
<Val><![CDATA[Property '{0}' cannot have an initializer because it is marked abstract.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[属性“{0}”不能具有初始化表杰式,因为它标记为摘要。]]></Val>
<Val><![CDATA[属性“{0}”不能具有初始化表达式,因为它标记为摘要。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2784,11 +2784,11 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations_9009" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9009" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[At least one accessor must have an explicit return type annotation with --isolatedDeclarations.]]></Val>
<Val><![CDATA[At least one accessor must have an explicit type annotation with --isolatedDeclarations.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[至少一個存取子必須有具備 --isolatedDeclarations 的明確傳回類型註解。]]></Val>
<Val><![CDATA[至少一個存取子必須有具備 --isolatedDeclarations 的明確型別註釋。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
Expand Down Expand Up @@ -5040,11 +5040,11 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_su_9025" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_its_type_This_is_not_sup_9025" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations.]]></Val>
<Val><![CDATA[Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[此參數發出的宣告需要隱含地新增未定義值至其類型。該情況不受 --isolatedDeclarations 支援。]]></Val>
<Val><![CDATA[此參數發出的宣告需要隱含地新增未定義值至其類型。此情況不受 --isolatedDeclarations 支援。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2793,11 +2793,11 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations_9009" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9009" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[At least one accessor must have an explicit return type annotation with --isolatedDeclarations.]]></Val>
<Val><![CDATA[At least one accessor must have an explicit type annotation with --isolatedDeclarations.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Alespoň jeden přistupující objekt musí mít explicitní anotaci návratového typu s možností --isolatedDeclarations.]]></Val>
<Val><![CDATA[Minimálně jeden přistupující objekt musí mít explicitní anotaci typu s možností --isolatedDeclarations.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
Expand Down Expand Up @@ -5049,11 +5049,11 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_su_9025" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_its_type_This_is_not_sup_9025" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations.]]></Val>
<Val><![CDATA[Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Generování deklarace pro tento parametr vyžaduje implicitně přidání možnosti „undefined“ do jeho typu. Toto není podporováno s možností --isolatedDeclarations.]]></Val>
<Val><![CDATA[Generování deklarace pro tento parametr vyžaduje implicitní přidání možnosti „undefined“ do jeho typu. Není podporováno s možností --isolatedDeclarations.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2781,11 +2781,11 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations_9009" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9009" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[At least one accessor must have an explicit return type annotation with --isolatedDeclarations.]]></Val>
<Val><![CDATA[At least one accessor must have an explicit type annotation with --isolatedDeclarations.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Mindestens ein Accessor muss eine explizite Rückgabetypanmerkung mit "--isolatedDeclarations" aufweisen.]]></Val>
<Val><![CDATA[Mindestens ein Accessor muss über eine explizite Typanmerkung mit --isolatedDeclarations“ verfügen.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
Expand Down Expand Up @@ -5037,11 +5037,11 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_su_9025" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_its_type_This_is_not_sup_9025" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations.]]></Val>
<Val><![CDATA[Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Die Deklarationsausgabe für diesen Parameter erfordert das implizit undefinierte Hinzufügen zum Typ. Dies wird mit "--isolatedDeclarations" nicht unterstützt.]]></Val>
<Val><![CDATA[Die Deklarationsausgabe für diesen Parameter erfordert das implizit undefinierte Hinzufügen zum Typ. Dies wird mit --isolatedDeclarations nicht unterstützt.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2796,11 +2796,11 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations_9009" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9009" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[At least one accessor must have an explicit return type annotation with --isolatedDeclarations.]]></Val>
<Val><![CDATA[At least one accessor must have an explicit type annotation with --isolatedDeclarations.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Al menos un descriptor de acceso debe tener una anotación de tipo de valor devuelto explícita con --isolatedDeclarations.]]></Val>
<Val><![CDATA[Al menos un descriptor de acceso debe tener una anotación de tipo explícita con --isolatedDeclarations.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
Expand Down Expand Up @@ -5052,9 +5052,9 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_su_9025" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_its_type_This_is_not_sup_9025" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations.]]></Val>
<Val><![CDATA[Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[La emisión de declaración para este parámetro requiere agregar implícitamente un elemento no definido a su tipo. Esto no se admite con --isolatedDeclarations.]]></Val>
</Tgt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2796,11 +2796,11 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations_9009" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9009" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[At least one accessor must have an explicit return type annotation with --isolatedDeclarations.]]></Val>
<Val><![CDATA[At least one accessor must have an explicit type annotation with --isolatedDeclarations.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Au moins un accesseur doit avoir une annotation de type de retour explicite avec --isolatedDeclarations.]]></Val>
<Val><![CDATA[Au moins un accesseur doit avoir une annotation de type explicite avec --isolatedDeclarations.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
Expand Down Expand Up @@ -5052,11 +5052,11 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_su_9025" ItemType="0" PsrId="306" Leaf="true">
<Item ItemId=";Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_its_type_This_is_not_sup_9025" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations.]]></Val>
<Val><![CDATA[Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[L’émission de déclaration pour ce paramètre nécessite l’ajout implicite non défini à son type. Cette opération n’est pas pris en charge avec --isolatedDeclarations.]]></Val>
<Val><![CDATA[L’émission de déclaration pour ce paramètre nécessite l’ajout implicite de « non défini » à son type. Cette opération n’est pas pris en charge avec --isolatedDeclarations.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
Expand Down
Loading