mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-25 22:01:51 -05:00
addressed PR feedback
This commit is contained in:
@@ -14246,7 +14246,7 @@ namespace ts {
|
||||
if (checkBody) {
|
||||
// body of ambient external module is always a module block
|
||||
for (const statement of (<ModuleBlock>node.body).statements) {
|
||||
checkBodyOfModuleAugmentation(statement, isGlobalAugmentation);
|
||||
checkModuleAugmentationElement(statement, isGlobalAugmentation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14273,20 +14273,12 @@ namespace ts {
|
||||
checkSourceElement(node.body);
|
||||
}
|
||||
|
||||
function checkBodyOfModuleAugmentation(node: Node, isGlobalAugmentation: boolean): void {
|
||||
function checkModuleAugmentationElement(node: Node, isGlobalAugmentation: boolean): void {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.VariableStatement:
|
||||
// error each individual name in variable statement instead of marking the entire variable statement
|
||||
for (const decl of (<VariableStatement>node).declarationList.declarations) {
|
||||
if (isBindingPattern(decl.name)) {
|
||||
for (const el of (<BindingPattern>decl.name).elements) {
|
||||
// mark individual names in binding pattern
|
||||
checkBodyOfModuleAugmentation(el, isGlobalAugmentation);
|
||||
}
|
||||
}
|
||||
else {
|
||||
checkBodyOfModuleAugmentation(decl, isGlobalAugmentation);
|
||||
}
|
||||
checkModuleAugmentationElement(decl, isGlobalAugmentation);
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.ExportAssignment:
|
||||
@@ -14302,7 +14294,23 @@ namespace ts {
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
grammarErrorOnFirstToken(node, Diagnostics.Imports_are_not_permitted_in_module_augmentations_Consider_moving_them_to_the_enclosing_external_module);
|
||||
break;
|
||||
default:
|
||||
case SyntaxKind.BindingElement:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
const name = (<VariableDeclaration | BindingElement>node).name;
|
||||
if (isBindingPattern(name)) {
|
||||
for (const el of name.elements) {
|
||||
// mark individual names in binding pattern
|
||||
checkModuleAugmentationElement(el, isGlobalAugmentation);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
const symbol = getSymbolOfNode(node);
|
||||
if (symbol) {
|
||||
// module augmentations cannot introduce new names on the top level scope of the module
|
||||
|
||||
@@ -527,13 +527,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (resolveModuleNamesWorker) {
|
||||
const moduleNames: string[] = [];
|
||||
for (const moduleName of newSourceFile.imports) {
|
||||
moduleNames.push(moduleName.text);
|
||||
}
|
||||
for (const moduleName of newSourceFile.moduleAugmentations) {
|
||||
moduleNames.push(moduleName.text);
|
||||
}
|
||||
const moduleNames = map(concatenate(newSourceFile.imports, newSourceFile.moduleAugmentations), getTextOfLiteral);
|
||||
const resolutions = resolveModuleNamesWorker(moduleNames, getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory));
|
||||
// ensure that module resolution results are still correct
|
||||
for (let i = 0; i < moduleNames.length; i++) {
|
||||
@@ -922,6 +916,10 @@ namespace ts {
|
||||
return a.text === b.text;
|
||||
}
|
||||
|
||||
function getTextOfLiteral(literal: LiteralExpression): string {
|
||||
return literal.text;
|
||||
}
|
||||
|
||||
function collectExternalModuleReferences(file: SourceFile): void {
|
||||
if (file.imports) {
|
||||
return;
|
||||
@@ -1128,13 +1126,7 @@ namespace ts {
|
||||
collectExternalModuleReferences(file);
|
||||
if (file.imports.length || file.moduleAugmentations.length) {
|
||||
file.resolvedModules = {};
|
||||
const moduleNames: string[] = [];
|
||||
for (const name of file.imports) {
|
||||
moduleNames.push(name.text);
|
||||
}
|
||||
for (const name of file.moduleAugmentations) {
|
||||
moduleNames.push(name.text);
|
||||
}
|
||||
const moduleNames = map(concatenate(file.imports, file.moduleAugmentations), getTextOfLiteral);
|
||||
const resolutions = resolveModuleNamesWorker(moduleNames, getNormalizedAbsolutePath(file.fileName, currentDirectory));
|
||||
for (let i = 0; i < moduleNames.length; i++) {
|
||||
const resolution = resolutions[i];
|
||||
|
||||
@@ -3,6 +3,10 @@ tests/cases/compiler/x.ts(8,9): error TS2663: Module augmentation cannot introdu
|
||||
tests/cases/compiler/x.ts(9,11): error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
tests/cases/compiler/x.ts(10,10): error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
tests/cases/compiler/x.ts(10,14): error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
tests/cases/compiler/x.ts(10,23): error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
tests/cases/compiler/x.ts(10,38): error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
tests/cases/compiler/x.ts(10,43): error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
tests/cases/compiler/x.ts(10,48): error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
tests/cases/compiler/x.ts(11,15): error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
tests/cases/compiler/x.ts(12,15): error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
tests/cases/compiler/x.ts(15,11): error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
@@ -23,7 +27,7 @@ tests/cases/compiler/x.ts(25,5): error TS2664: Exports and export assignments ar
|
||||
|
||||
export let a = 1;
|
||||
|
||||
==== tests/cases/compiler/x.ts (19 errors) ====
|
||||
==== tests/cases/compiler/x.ts (23 errors) ====
|
||||
|
||||
namespace N1 {
|
||||
export let x = 1;
|
||||
@@ -39,10 +43,18 @@ tests/cases/compiler/x.ts(25,5): error TS2664: Exports and export assignments ar
|
||||
const z: number;
|
||||
~
|
||||
!!! error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
let {x1, y1}: {x1: number, y1: string}
|
||||
let {x1, y1, z0: {n}, z1: {arr: [el1, el2, el3]}}: {x1: number, y1: string, z0: {n: number}, z1: {arr: number[]} }
|
||||
~~
|
||||
!!! error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
~~
|
||||
!!! error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
~
|
||||
!!! error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
~~~
|
||||
!!! error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
~~~
|
||||
!!! error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
~~~
|
||||
!!! error TS2663: Module augmentation cannot introduce new names in the top level scope.
|
||||
interface A { x }
|
||||
~
|
||||
|
||||
@@ -14,7 +14,7 @@ declare module "./observable" {
|
||||
var x: number;
|
||||
let y: number;
|
||||
const z: number;
|
||||
let {x1, y1}: {x1: number, y1: string}
|
||||
let {x1, y1, z0: {n}, z1: {arr: [el1, el2, el3]}}: {x1: number, y1: string, z0: {n: number}, z1: {arr: number[]} }
|
||||
interface A { x }
|
||||
namespace N {
|
||||
export class C {}
|
||||
|
||||
@@ -13,7 +13,7 @@ declare module "./observable" {
|
||||
var x: number;
|
||||
let y: number;
|
||||
const z: number;
|
||||
let {x1, y1}: {x1: number, y1: string}
|
||||
let {x1, y1, z0: {n}, z1: {arr: [el1, el2, el3]}}: {x1: number, y1: string, z0: {n: number}, z1: {arr: number[]} }
|
||||
interface A { x }
|
||||
namespace N {
|
||||
export class C {}
|
||||
|
||||
Reference in New Issue
Block a user