Skip to content

Commit 19d7309

Browse files
author
Andy Hanson
committed
Merge branch 'master' into moveToNewFile
2 parents 886a937 + 27550d3 commit 19d7309

File tree

220 files changed

+4947
-706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+4947
-706
lines changed

src/compiler/binder.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ namespace ts {
281281
return InternalSymbolName.Index;
282282
case SyntaxKind.ExportDeclaration:
283283
return InternalSymbolName.ExportStar;
284+
case SyntaxKind.SourceFile:
285+
// json file should behave as
286+
// module.exports = ...
287+
return InternalSymbolName.ExportEquals;
284288
case SyntaxKind.BinaryExpression:
285289
if (getSpecialPropertyAssignmentKind(node as BinaryExpression) === SpecialPropertyAssignmentKind.ModuleExports) {
286290
// module.exports = ...
@@ -2234,6 +2238,13 @@ namespace ts {
22342238
if (isExternalModule(file)) {
22352239
bindSourceFileAsExternalModule();
22362240
}
2241+
else if (isJsonSourceFile(file)) {
2242+
bindSourceFileAsExternalModule();
2243+
// Create symbol equivalent for the module.exports = {}
2244+
const originalSymbol = file.symbol;
2245+
declareSymbol(file.symbol.exports, file.symbol, file, SymbolFlags.Property, SymbolFlags.All);
2246+
file.symbol = originalSymbol;
2247+
}
22372248
}
22382249

22392250
function bindSourceFileAsExternalModule() {

src/compiler/checker.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,7 +2207,7 @@ namespace ts {
22072207
}
22082208

22092209
// May be an untyped module. If so, ignore resolutionDiagnostic.
2210-
if (resolvedModule && !extensionIsTypeScript(resolvedModule.extension) && resolutionDiagnostic === undefined || resolutionDiagnostic === Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type) {
2210+
if (resolvedModule && !resolutionExtensionIsTypeScriptOrJson(resolvedModule.extension) && resolutionDiagnostic === undefined || resolutionDiagnostic === Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type) {
22112211
if (isForAugmentation) {
22122212
const diag = Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented;
22132213
error(errorNode, diag, moduleReference, resolvedModule.resolvedFileName);
@@ -2220,7 +2220,22 @@ namespace ts {
22202220
}
22212221

22222222
if (moduleNotFoundError) {
2223-
// report errors only if it was requested
2223+
// For relative paths, see if this was possibly a projectReference redirect
2224+
if (pathIsRelative(moduleReference)) {
2225+
const sourceFile = getSourceFileOfNode(location);
2226+
const redirects = sourceFile.redirectedReferences;
2227+
if (redirects) {
2228+
const normalizedTargetPath = getNormalizedAbsolutePath(moduleReference, getDirectoryPath(sourceFile.fileName));
2229+
for (const ext of [Extension.Ts, Extension.Tsx]) {
2230+
const probePath = normalizedTargetPath + ext;
2231+
if (redirects.indexOf(probePath) >= 0) {
2232+
error(errorNode, Diagnostics.Output_file_0_has_not_been_built_from_source_file_1, moduleReference, probePath);
2233+
return undefined;
2234+
}
2235+
}
2236+
}
2237+
}
2238+
22242239
if (resolutionDiagnostic) {
22252240
error(errorNode, resolutionDiagnostic, moduleReference, resolvedModule.resolvedFileName);
22262241
}
@@ -4718,6 +4733,10 @@ namespace ts {
47184733
return links.type = anyType;
47194734
}
47204735
// Handle export default expressions
4736+
if (isSourceFile(declaration)) {
4737+
const jsonSourceFile = cast(declaration, isJsonSourceFile);
4738+
return links.type = jsonSourceFile.statements.length ? checkExpression(jsonSourceFile.statements[0].expression) : emptyObjectType;
4739+
}
47214740
if (declaration.kind === SyntaxKind.ExportAssignment) {
47224741
return links.type = checkExpression((<ExportAssignment>declaration).expression);
47234742
}
@@ -6501,9 +6520,9 @@ namespace ts {
65016520
// over the conditional type and possibly reduced. For example, 'T extends undefined ? never : T'
65026521
// removes 'undefined' from T.
65036522
if (type.root.isDistributive) {
6504-
const constraint = getConstraintOfType(type.checkType);
6523+
const constraint = getConstraintOfType(getSimplifiedType(type.checkType));
65056524
if (constraint) {
6506-
const mapper = createTypeMapper([<TypeParameter>type.root.checkType], [constraint]);
6525+
const mapper = makeUnaryTypeMapper(type.root.checkType, constraint);
65076526
const instantiated = getConditionalTypeInstantiation(type, combineTypeMappers(mapper, type.mapper));
65086527
if (!(instantiated.flags & TypeFlags.Never)) {
65096528
return instantiated;
@@ -15597,7 +15616,7 @@ namespace ts {
1559715616
const contextualType = getApparentTypeOfContextualType(node);
1559815617
const contextualTypeHasPattern = contextualType && contextualType.pattern &&
1559915618
(contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern || contextualType.pattern.kind === SyntaxKind.ObjectLiteralExpression);
15600-
const isInJSFile = isInJavaScriptFile(node);
15619+
const isInJSFile = isInJavaScriptFile(node) && !isInJsonFile(node);
1560115620
const isJSObjectLiteral = !contextualType && isInJSFile;
1560215621
let typeFlags: TypeFlags = 0;
1560315622
let patternWithComputedProperties = false;

0 commit comments

Comments
 (0)