@@ -25,6 +25,7 @@ import (
2525 "github.com/microsoft/typescript-go/internal/printer"
2626 "github.com/microsoft/typescript-go/internal/scanner"
2727 "github.com/microsoft/typescript-go/internal/stringutil"
28+ "github.com/microsoft/typescript-go/internal/tsoptions"
2829 "github.com/microsoft/typescript-go/internal/tspath"
2930)
3031
@@ -527,6 +528,7 @@ type Program interface {
527528 BindSourceFiles()
528529 FileExists(fileName string) bool
529530 GetSourceFile(fileName string) *ast.SourceFile
531+ GetSourceFileForResolvedModule(fileName string) *ast.SourceFile
530532 GetEmitModuleFormatOfFile(sourceFile ast.HasFileName) core.ModuleKind
531533 GetEmitSyntaxForUsageLocation(sourceFile ast.HasFileName, usageLocation *ast.StringLiteralLike) core.ResolutionMode
532534 GetImpliedNodeFormatForEmit(sourceFile ast.HasFileName) core.ModuleKind
@@ -535,6 +537,8 @@ type Program interface {
535537 GetSourceFileMetaData(path tspath.Path) *ast.SourceFileMetaData
536538 GetJSXRuntimeImportSpecifier(path tspath.Path) (moduleReference string, specifier *ast.Node)
537539 GetImportHelpersImportSpecifier(path tspath.Path) *ast.Node
540+ IsSourceFromProjectReference(path tspath.Path) bool
541+ GetSourceAndProjectReference(path tspath.Path) *tsoptions.SourceAndProjectReference
538542}
539543
540544type Host interface {
@@ -2086,7 +2090,7 @@ func (c *Checker) getSymbol(symbols ast.SymbolTable, name string, meaning ast.Sy
20862090}
20872091
20882092func (c *Checker) CheckSourceFile(ctx context.Context, sourceFile *ast.SourceFile) {
2089- if SkipTypeChecking(sourceFile, c.compilerOptions) {
2093+ if SkipTypeChecking(sourceFile, c.compilerOptions, c.program ) {
20902094 return
20912095 }
20922096 c.checkSourceFile(ctx, sourceFile)
@@ -6462,15 +6466,13 @@ func (c *Checker) checkAliasSymbol(node *ast.Node) {
64626466 // in files that are unambiguously CommonJS in this mode.
64636467 c.error(node, diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve)
64646468 }
6465- // !!!
6466-
6467- // if c.compilerOptions.VerbatimModuleSyntax.IsTrue() && !ast.IsTypeOnlyImportOrExportDeclaration(node) && node.Flags&ast.NodeFlagsAmbient == 0 && targetFlags&ast.SymbolFlagsConstEnum != 0 {
6468- // constEnumDeclaration := target.ValueDeclaration
6469- // redirect := host.getRedirectReferenceForResolutionFromSourceOfProject(ast.GetSourceFileOfNode(constEnumDeclaration).ResolvedPath)
6470- // if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && (redirect == nil || !shouldPreserveConstEnums(redirect.commandLine.options)) {
6471- // c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
6472- // }
6473- // }
6469+ if c.compilerOptions.VerbatimModuleSyntax.IsTrue() && !ast.IsTypeOnlyImportOrExportDeclaration(node) && node.Flags&ast.NodeFlagsAmbient == 0 && targetFlags&ast.SymbolFlagsConstEnum != 0 {
6470+ constEnumDeclaration := target.ValueDeclaration
6471+ redirect := c.program.GetSourceAndProjectReference(ast.GetSourceFileOfNode(constEnumDeclaration).Path())
6472+ if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && (redirect == nil || !redirect.Resolved.CompilerOptions().ShouldPreserveConstEnums()) {
6473+ c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
6474+ }
6475+ }
64746476 }
64756477 if ast.IsImportSpecifier(node) {
64766478 targetSymbol := c.resolveAliasWithDeprecationCheck(symbol, node)
@@ -7184,15 +7186,14 @@ func (c *Checker) checkConstEnumAccess(node *ast.Node, t *Type) {
71847186 // --verbatimModuleSyntax only gets checked here when the enum usage does not
71857187 // resolve to an import, because imports of ambient const enums get checked
71867188 // separately in `checkAliasSymbol`.
7187- // !!!
7188- // if c.compilerOptions.IsolatedModules.IsTrue() || c.compilerOptions.VerbatimModuleSyntax.IsTrue() && ok && c.resolveName(node, getFirstIdentifier(node).Text(), ast.SymbolFlagsAlias, nil, false, true) == nil {
7189- // // Debug.assert(t.symbol.Flags&ast.SymbolFlagsConstEnum != 0)
7190- // constEnumDeclaration := t.symbol.ValueDeclaration
7191- // redirect := host.getRedirectReferenceForResolutionFromSourceOfProject(ast.GetSourceFileOfNode(constEnumDeclaration).ResolvedPath)
7192- // if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && !isValidTypeOnlyAliasUseSite(node) && (redirect == nil || !shouldPreserveConstEnums(redirect.commandLine.options)) {
7193- // c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
7194- // }
7195- // }
7189+ if c.compilerOptions.IsolatedModules.IsTrue() || c.compilerOptions.VerbatimModuleSyntax.IsTrue() && ok && c.resolveName(node, ast.GetFirstIdentifier(node).Text(), ast.SymbolFlagsAlias, nil, false, true) == nil {
7190+ // Debug.assert(t.symbol.Flags&ast.SymbolFlagsConstEnum != 0)
7191+ constEnumDeclaration := t.symbol.ValueDeclaration
7192+ redirect := c.program.GetSourceAndProjectReference(ast.GetSourceFileOfNode(constEnumDeclaration).Path())
7193+ if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && !ast.IsValidTypeOnlyAliasUseSite(node) && (redirect == nil || !redirect.Resolved.CompilerOptions().ShouldPreserveConstEnums()) {
7194+ c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName())
7195+ }
7196+ }
71967197}
71977198
71987199func (c *Checker) instantiateTypeWithSingleGenericCallSignature(node *ast.Node, t *Type, checkMode CheckMode) *Type {
@@ -14467,7 +14468,7 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
1446714468 var sourceFile *ast.SourceFile
1446814469 resolvedModule := c.program.GetResolvedModule(importingSourceFile, moduleReference, mode)
1446914470 if resolvedModule.IsResolved() {
14470- sourceFile = c.program.GetSourceFile (resolvedModule.ResolvedFileName)
14471+ sourceFile = c.program.GetSourceFileForResolvedModule (resolvedModule.ResolvedFileName)
1447114472 }
1447214473
1447314474 if sourceFile != nil {
@@ -14573,6 +14574,21 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
1457314574 }
1457414575
1457514576 if moduleNotFoundError != nil {
14577+
14578+ // See if this was possibly a projectReference redirect
14579+ if resolvedModule.IsResolved() {
14580+ redirect := c.program.GetOutputAndProjectReference(tspath.ToPath(resolvedModule.ResolvedFileName, c.program.GetCurrentDirectory(), c.program.UseCaseSensitiveFileNames()))
14581+ if redirect != nil && redirect.OutputDts != "" {
14582+ c.error(
14583+ errorNode,
14584+ diagnostics.Output_file_0_has_not_been_built_from_source_file_1,
14585+ redirect.OutputDts,
14586+ resolvedModule.ResolvedFileName,
14587+ )
14588+ return nil
14589+ }
14590+ }
14591+
1457614592 // !!!
1457714593 isExtensionlessRelativePathImport := tspath.PathIsRelative(moduleReference) && !tspath.HasExtension(moduleReference)
1457814594 resolutionIsNode16OrNext := c.moduleResolutionKind == core.ModuleResolutionKindNode16 || c.moduleResolutionKind == core.ModuleResolutionKindNodeNext
0 commit comments