CR feedback

This commit is contained in:
Ryan Cavanaugh
2015-10-19 11:02:20 -07:00
parent 61b71008d7
commit 5725fc4497
9 changed files with 119 additions and 476 deletions
+4 -14
View File
@@ -2577,7 +2577,7 @@ namespace ts {
return links.type = checkExpression((<BinaryExpression>declaration).right);
}
// Handle exports.p = expr
if (declaration.kind === SyntaxKind.PropertyAccessExpression && declaration.parent.kind === SyntaxKind.BinaryExpression) {
if (declaration.kind === SyntaxKind.PropertyAccessExpression) {
return checkExpressionCached((<BinaryExpression>declaration.parent).right);
}
// Handle variable, parameter or property
@@ -9377,11 +9377,9 @@ namespace ts {
}
}
let exprType = checkExpression(node.expression);
if (exprType === cjsRequireType) {
if (node.arguments.length === 1 && node.arguments[0].kind === SyntaxKind.StringLiteral) {
return resolveExternalModuleTypeByLiteral(<StringLiteral>node.arguments[0]);
}
// In JavaScript files, calls to any identifier 'require' are treated as external module imports
if (isInJavaScriptFile(node) && isRequireCall(node)) {
return resolveExternalModuleTypeByLiteral(<StringLiteral>node.arguments[0]);
}
return getReturnTypeOfSignature(signature);
@@ -14925,14 +14923,6 @@ namespace ts {
}
});
// Initialize special symbols
if (compilerOptions.allowNonTsExtensions) {
let req = getExportedSymbolFromNamespace("CommonJS", "require");
if (req) {
globals["require"] = req;
}
}
getSymbolLinks(undefinedSymbol).type = undefinedType;
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments");
getSymbolLinks(unknownSymbol).type = unknownType;
+3 -2
View File
@@ -1039,7 +1039,7 @@ namespace ts {
return isInJavaScriptFile(file);
}
function isInJavaScriptFile(node: Node): boolean {
export function isInJavaScriptFile(node: Node): boolean {
return node && !!(node.parserContextFlags & ParserContextFlags.JavaScriptFile);
}
@@ -1053,7 +1053,8 @@ namespace ts {
return expression.kind === SyntaxKind.CallExpression &&
(<CallExpression>expression).expression.kind === SyntaxKind.Identifier &&
(<Identifier>(<CallExpression>expression).expression).text === "require" &&
(<CallExpression>expression).arguments.length === 1;
(<CallExpression>expression).arguments.length === 1 &&
(<CallExpression>expression).arguments[0].kind === SyntaxKind.StringLiteral;
}
/**
-16
View File
@@ -1183,22 +1183,6 @@ interface PromiseLike<T> {
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>;
}
declare namespace CommonJS {
export var require: Require;
export var exports: any;
interface Exports { }
interface Module {
exports: Exports;
}
interface Require {
(moduleName: string): any;
}
}
interface ArrayLike<T> {
length: number;
[n: number]: T;