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
2 changes: 1 addition & 1 deletion microsoft/typescript-go
Submodule typescript-go updated 134 files
4 changes: 3 additions & 1 deletion pkg/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -10757,7 +10757,9 @@ type SourceFile struct {
NodeCount int
TextCount int
CommonJSModuleIndicator *Node
ExternalModuleIndicator *Node
// If this is the SourceFile itself, then this module was "forced"
// to be an external module (previously "true").
ExternalModuleIndicator *Node

// Fields set by binder

Expand Down
1 change: 0 additions & 1 deletion pkg/ast/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ const (
KindEnumMember
// Top-level nodes
KindSourceFile
KindBundle
// JSDoc nodes
KindJSDocTypeExpression
KindJSDocNameReference
Expand Down
99 changes: 49 additions & 50 deletions pkg/ast/kind_stringer_generated.go

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions pkg/binder/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,9 @@ func (b *Binder) bind(node *ast.Node) bool {
case ast.KindInterfaceDeclaration:
b.bindBlockScopedDeclaration(node, ast.SymbolFlagsInterface, ast.SymbolFlagsInterfaceExcludes)
case ast.KindCallExpression:
b.bindCallExpression(node)
if ast.IsInJSFile(node) {
b.bindCallExpression(node)
}
case ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration:
b.bindBlockScopedDeclaration(node, ast.SymbolFlagsTypeAlias, ast.SymbolFlagsTypeAliasExcludes)
case ast.KindEnumDeclaration:
Expand Down Expand Up @@ -910,16 +912,24 @@ func (b *Binder) bindFunctionExpression(node *ast.Node) {
}

func (b *Binder) bindCallExpression(node *ast.Node) {
// !!! for ModuleDetectionKind.Force, external module indicator is forced to `true` in Strada for source files, in which case
// we should set the commonjs module indicator but not call b.bindSourceFileAsExternalModule
// !!! && file.externalModuleIndicator !== true (used for ModuleDetectionKind.Force)
if ast.IsInJSFile(node) &&
b.file.ExternalModuleIndicator == nil &&
b.file.CommonJSModuleIndicator == nil &&
ast.IsRequireCall(node, false /*requireStringLiteralLikeArgument*/) {
// We're only inspecting call expressions to detect CommonJS modules, so we can skip
// this check if we've already seen the module indicator
if b.file.CommonJSModuleIndicator == nil && ast.IsRequireCall(node, false /*requireStringLiteralLikeArgument*/) {
b.setCommonJSModuleIndicator(node)
}
}

func (b *Binder) setCommonJSModuleIndicator(node *ast.Node) bool {
if b.file.ExternalModuleIndicator != nil && b.file.ExternalModuleIndicator != b.file.AsNode() {
return false
}
if b.file.CommonJSModuleIndicator == nil {
b.file.CommonJSModuleIndicator = node
b.bindSourceFileAsExternalModule()
if b.file.ExternalModuleIndicator == nil {
b.bindSourceFileAsExternalModule()
}
}
return true
}

func (b *Binder) bindClassLikeDeclaration(node *ast.Node) {
Expand Down
60 changes: 51 additions & 9 deletions pkg/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ func isSameScopeDescendentOf(initial *ast.Node, parent *ast.Node, stopAt *ast.No
return false
}

// stopAtAnyPropertyDeclaration is used for detecting ES-standard class field use-before-def errors
// isPropertyImmediatelyReferencedWithinDeclaration is used for detecting ES-standard class field use-before-def errors
func isPropertyImmediatelyReferencedWithinDeclaration(declaration *ast.Node, usage *ast.Node, stopAtAnyPropertyDeclaration bool) bool {
// always legal if usage is after declaration
if usage.End() > declaration.End() {
Expand Down Expand Up @@ -5539,7 +5539,7 @@ func (c *Checker) checkExternalModuleExports(node *ast.Node) {
links := c.moduleSymbolLinks.Get(moduleSymbol)
if !links.exportsChecked {
exportEqualsSymbol := moduleSymbol.Exports[ast.InternalSymbolNameExportEquals]
if exportEqualsSymbol != nil && c.hasExportedMembers(moduleSymbol) {
if exportEqualsSymbol != nil && c.hasExportedMembers(moduleSymbol, exportEqualsSymbol.ValueDeclaration.Kind == ast.KindJSExportAssignment) {
declaration := core.OrElse(c.getDeclarationOfAliasSymbol(exportEqualsSymbol), exportEqualsSymbol.ValueDeclaration)
if declaration != nil && !isTopLevelInExternalModuleAugmentation(declaration) {
c.error(declaration, diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements)
Expand Down Expand Up @@ -5575,10 +5575,17 @@ func (c *Checker) checkExternalModuleExports(node *ast.Node) {
}
}

func (c *Checker) hasExportedMembers(moduleSymbol *ast.Symbol) bool {
func (c *Checker) hasExportedMembers(moduleSymbol *ast.Symbol, isCommonJS bool) bool {
for id := range moduleSymbol.Exports {
if id != ast.InternalSymbolNameExportEquals {
return true
if !isCommonJS {
return true
}
for _, declaration := range moduleSymbol.Exports[id].Declarations {
if declaration.Kind != ast.KindJSTypeAliasDeclaration {
return true
}
}
}
}
return false
Expand Down Expand Up @@ -14440,7 +14447,7 @@ func (c *Checker) canHaveSyntheticDefault(file *ast.Node, moduleSymbol *ast.Symb
}

// JS files have a synthetic default if they do not contain ES2015+ module syntax (export = is not valid in js) _and_ do not have an __esModule marker
return !ast.IsExternalModule(file.AsSourceFile()) && c.resolveExportByName(moduleSymbol, "__esModule", nil /*sourceNode*/, dontResolveAlias) == nil
return (file.AsSourceFile().ExternalModuleIndicator == nil || file.AsSourceFile().ExternalModuleIndicator == file) && c.resolveExportByName(moduleSymbol, "__esModule", nil /*sourceNode*/, dontResolveAlias) == nil
}

func (c *Checker) getEmitSyntaxForModuleSpecifierExpression(usage *ast.Node) core.ResolutionMode {
Expand Down Expand Up @@ -15333,13 +15340,27 @@ func (c *Checker) resolveEntityName(name *ast.Node, meaning ast.SymbolFlags, ign
if resolveLocation == nil {
resolveLocation = name
}
symbol = c.getMergedSymbol(c.resolveName(resolveLocation, name.Text(), meaning, message, true /*isUse*/, false /*excludeGlobals*/))
if meaning == ast.SymbolFlagsNamespace {
symbol = c.getMergedSymbol(c.resolveName(resolveLocation, name.Text(), meaning, nil, true /*isUse*/, false /*excludeGlobals*/))
if symbol == nil {
alias := c.getMergedSymbol(c.resolveName(resolveLocation, name.Text(), ast.SymbolFlagsAlias, nil, true /*isUse*/, false /*excludeGlobals*/))
if alias != nil && alias.Name == ast.InternalSymbolNameExportEquals {
// resolve typedefs exported from commonjs, stored on the module symbol
symbol = alias.Parent
}
}
if symbol == nil && message != nil {
c.resolveName(resolveLocation, name.Text(), meaning, message, true /*isUse*/, false /*excludeGlobals*/)
}
} else {
symbol = c.getMergedSymbol(c.resolveName(resolveLocation, name.Text(), meaning, message, true /*isUse*/, false /*excludeGlobals*/))
}
case ast.KindQualifiedName:
qualified := name.AsQualifiedName()
symbol = c.resolveQualifiedName(name, qualified.Left, qualified.Right, meaning, ignoreErrors, dontResolveAlias, location)
symbol = c.resolveQualifiedName(name, qualified.Left, qualified.Right, meaning, ignoreErrors, location)
case ast.KindPropertyAccessExpression:
access := name.AsPropertyAccessExpression()
symbol = c.resolveQualifiedName(name, access.Expression, access.Name(), meaning, ignoreErrors, dontResolveAlias, location)
symbol = c.resolveQualifiedName(name, access.Expression, access.Name(), meaning, ignoreErrors, location)
default:
panic("Unknown entity name kind")
}
Expand All @@ -15357,7 +15378,7 @@ func (c *Checker) resolveEntityName(name *ast.Node, meaning ast.SymbolFlags, ign
return symbol
}

func (c *Checker) resolveQualifiedName(name *ast.Node, left *ast.Node, right *ast.Node, meaning ast.SymbolFlags, ignoreErrors bool, dontResolveAlias bool, location *ast.Node) *ast.Symbol {
func (c *Checker) resolveQualifiedName(name *ast.Node, left *ast.Node, right *ast.Node, meaning ast.SymbolFlags, ignoreErrors bool, location *ast.Node) *ast.Symbol {
namespace := c.resolveEntityName(left, ast.SymbolFlagsNamespace, ignoreErrors, false /*dontResolveAlias*/, location)
if namespace == nil || ast.NodeIsMissing(right) {
return nil
Expand Down Expand Up @@ -15713,12 +15734,26 @@ func (c *Checker) getExportsOfModuleWorker(moduleSymbol *ast.Symbol) (exports as
}
return symbols
}
var originalModule *ast.Symbol
if moduleSymbol != nil {
if c.resolveSymbolEx(moduleSymbol.Exports[ast.InternalSymbolNameExportEquals], false /*dontResolveAlias*/) != nil {
originalModule = moduleSymbol
}
}
// A module defined by an 'export=' consists of one export that needs to be resolved
moduleSymbol = c.resolveExternalModuleSymbol(moduleSymbol, false /*dontResolveAlias*/)
exports = visit(moduleSymbol, nil, false)
if exports == nil {
exports = make(ast.SymbolTable)
}
// A CommonJS module defined by an 'export=' might also export typedefs, stored on the original module
if originalModule != nil && len(originalModule.Exports) > 1 {
for _, symbol := range originalModule.Exports {
if symbol.Flags&ast.SymbolFlagsType != 0 && symbol.Name != ast.InternalSymbolNameExportEquals && exports[symbol.Name] == nil {
exports[symbol.Name] = symbol
}
}
}
for name := range nonTypeOnlyNames.Keys() {
delete(typeOnlyExportStarMap, name)
}
Expand Down Expand Up @@ -23972,6 +24007,13 @@ func (c *Checker) getTypeFromImportTypeNode(node *ast.Node) *Type {
symbolFromVariable = c.getPropertyOfTypeEx(c.getTypeOfSymbol(mergedResolvedSymbol), current.Text(), false /*skipObjectFunctionPropertyAugment*/, true /*includeTypeOnlyMembers*/)
} else {
symbolFromModule = c.getSymbol(c.getExportsOfSymbol(mergedResolvedSymbol), current.Text(), meaning)
if symbolFromModule == nil {
// a CommonJS module might have typedefs exported alongside an export=
immediateModuleSymbol := c.resolveExternalModuleSymbol(innerModuleSymbol, true /*dontResolveAlias*/)
if immediateModuleSymbol != nil && core.Some(immediateModuleSymbol.Declarations, func(d *ast.Node) bool { return d.Kind == ast.KindJSExportAssignment }) {
symbolFromModule = c.getSymbol(c.getExportsOfSymbol(immediateModuleSymbol.Parent), current.Text(), meaning)
}
}
}
next := core.OrElse(symbolFromModule, symbolFromVariable)
if next == nil {
Expand Down
4 changes: 1 addition & 3 deletions pkg/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2093,9 +2093,7 @@ func (c *Checker) checkGrammarNumericLiteral(node *ast.NumericLiteral) {
// We should test against `getTextOfNode(node)` rather than `node.text`, because `node.text` for large numeric literals can contain "."
// e.g. `node.text` for numeric literal `1100000000000000000000` is `1.1e21`.
isFractional := strings.ContainsRune(nodeText, '.')
// !!!
// isScientific := node.NumericLiteralFlags & ast.TokenFlagsScientific
isScientific := strings.ContainsRune(nodeText, 'e')
isScientific := node.TokenFlags&ast.TokenFlagsScientific != 0

// Scientific notation (e.g. 2e54 and 1e00000000010) can't be converted to bigint
// Fractional numbers (e.g. 9000000000000000.001) are inherently imprecise anyway
Expand Down
8 changes: 0 additions & 8 deletions pkg/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,6 @@ func (b *NodeBuilderImpl) getSpecifierForModuleSymbol(symbol *ast.Symbol, overri
if ok {
return result
}
isBundle := false // !!! remove me
// For declaration bundles, we need to generate absolute paths relative to the common source dir for imports,
// just like how the declaration emitter does for the ambient module declarations - we can easily accomplish this
// using the `baseUrl` compiler option (which we would otherwise never use in declaration emit) and a non-relative
Expand All @@ -1191,13 +1190,6 @@ func (b *NodeBuilderImpl) getSpecifierForModuleSymbol(symbol *ast.Symbol, overri
if resolutionMode == core.ResolutionModeESM {
endingPref = modulespecifiers.ImportModuleSpecifierEndingPreferenceJs
}
if isBundle {
// !!! relies on option cloning and specifier host implementation
// specifierCompilerOptions = &core.CompilerOptions{BaseUrl: host.CommonSourceDirectory()}
// TODO: merge with b.ch.compilerOptions
specifierPref = modulespecifiers.ImportModuleSpecifierPreferenceNonRelative
endingPref = modulespecifiers.ImportModuleSpecifierEndingPreferenceMinimal
}

allSpecifiers := modulespecifiers.GetModuleSpecifiers(
symbol,
Expand Down
2 changes: 0 additions & 2 deletions pkg/evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func evaluateTemplateExpression(expr *ast.Node, location *ast.Node, evaluate Eva
}

func AnyToString(v any) string {
// !!! This function should behave identically to the expression `"" + v` in JS
switch v := v.(type) {
case string:
return v
Expand All @@ -155,7 +154,6 @@ func AnyToString(v any) string {
}

func IsTruthy(v any) bool {
// !!! This function should behave identically to the expression `!!v` in JS
switch v := v.(type) {
case string:
return len(v) != 0
Expand Down
1 change: 0 additions & 1 deletion pkg/execute/tsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

func CommandLine(sys tsc.System, commandLineArgs []string, testing tsc.CommandLineTesting) tsc.CommandLineResult {
if len(commandLineArgs) > 0 {
// !!! build mode
switch strings.ToLower(commandLineArgs[0]) {
case "-b", "--b", "-build", "--build":
return tscBuildCompilation(sys, tsoptions.ParseBuildCommandLine(commandLineArgs, sys), testing)
Expand Down
1 change: 0 additions & 1 deletion pkg/fourslash/_scripts/failingTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ TestIndexerReturnTypes1
TestIndirectClassInstantiation
TestInstanceTypesForGenericType1
TestJavascriptModules20
TestJavascriptModulesTypeImport
TestJsDocAugments
TestJsDocAugmentsAndExtends
TestJsdocCallbackTag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestJavascriptModulesTypeImport(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @allowJs: true
// @Filename: types.js
Expand Down
1 change: 0 additions & 1 deletion pkg/outputpaths/outputpaths.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (o *OutputPaths) DeclarationMapPath() string {
}

func GetOutputPathsFor(sourceFile *ast.SourceFile, options *core.CompilerOptions, host OutputPathsHost, forceDtsEmit bool) *OutputPaths {
// !!! bundle not implemented, may be deprecated
ownOutputFilePath := getOwnEmitOutputFilePath(sourceFile.FileName(), options, host, GetOutputExtension(sourceFile.FileName(), options.Jsx))
isJsonFile := ast.IsJsonSourceFile(sourceFile)
// If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it
Expand Down
9 changes: 5 additions & 4 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6457,7 +6457,7 @@ func (p *Parser) processPragmasIntoFields(context *ast.SourceFile) {
case typesOk:
var parsed core.ResolutionMode
if resolutionModeOk {
parsed = parseResolutionMode(resolutionMode.Value, resolutionMode.Pos(), resolutionMode.End() /*, reportDiagnostic*/)
parsed = p.parseResolutionMode(resolutionMode.Value, resolutionMode.Pos(), resolutionMode.End())
}
context.TypeReferenceDirectives = append(context.TypeReferenceDirectives, &ast.FileReference{
TextRange: types.TextRange,
Expand Down Expand Up @@ -6498,16 +6498,17 @@ func (p *Parser) processPragmasIntoFields(context *ast.SourceFile) {
}
}

func parseResolutionMode(mode string, pos int, end int /*reportDiagnostic: PragmaDiagnosticReporter*/) (resolutionKind core.ResolutionMode) {
func (p *Parser) parseResolutionMode(mode string, pos int, end int) (resolutionKind core.ResolutionMode) {
if mode == "import" {
resolutionKind = core.ModuleKindESNext
return resolutionKind
}
if mode == "require" {
resolutionKind = core.ModuleKindCommonJS
return resolutionKind
}
p.parseErrorAt(pos, end, diagnostics.X_resolution_mode_should_be_either_require_or_import)
return resolutionKind
// reportDiagnostic(pos, end - pos, Diagnostics.resolution_mode_should_be_either_require_or_import);
// return undefined;
}

func (p *Parser) jsErrorAtRange(loc core.TextRange, message *diagnostics.Message, args ...any) {
Expand Down
3 changes: 0 additions & 3 deletions pkg/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4951,9 +4951,6 @@ func (p *Printer) Write(node *ast.Node, sourceFile *ast.SourceFile, writer EmitT
case ast.KindSourceFile:
p.emitSourceFile(node.AsSourceFile())

case ast.KindBundle:
panic("not implemented")

// Transformation nodes
case ast.KindNotEmittedTypeElement:
p.emitNotEmittedTypeElement(node.AsNotEmittedTypeElement())
Expand Down
14 changes: 2 additions & 12 deletions pkg/transformers/declarations/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type DeclarationTransformer struct {
declarationFilePath string
declarationMapPath string

isBundledEmit bool
needsDeclare bool
needsScopeFixMarker bool
resultHasScopeMarker bool
Expand Down Expand Up @@ -102,7 +101,6 @@ func (tx *DeclarationTransformer) visit(node *ast.Node) *ast.Node {
if node == nil {
return nil
}
// !!! TODO: Bundle support?
switch node.Kind {
case ast.KindSourceFile:
return tx.visitSourceFile(node.AsSourceFile())
Expand Down Expand Up @@ -161,7 +159,6 @@ func (tx *DeclarationTransformer) visitSourceFile(node *ast.SourceFile) *ast.Nod
return node.AsNode()
}

tx.isBundledEmit = false
tx.needsDeclare = true
tx.needsScopeFixMarker = false
tx.resultHasScopeMarker = false
Expand Down Expand Up @@ -238,7 +235,7 @@ func (tx *DeclarationTransformer) transformAndReplaceLatePaintedStatements(state
tx.state.lateMarkedStatements = tx.state.lateMarkedStatements[1:]

saveNeedsDeclare := tx.needsDeclare
tx.needsDeclare = next.Parent != nil && ast.IsSourceFile(next.Parent) && !(ast.IsExternalModule(next.Parent.AsSourceFile()) && tx.isBundledEmit)
tx.needsDeclare = next.Parent != nil && ast.IsSourceFile(next.Parent)

result := tx.transformTopLevelDeclaration(next)

Expand Down Expand Up @@ -311,8 +308,6 @@ func (tx *DeclarationTransformer) getReferencedFiles(outputFilePath string) (res
if file.IsDeclarationFile {
declFileName = file.FileName()
} else {
// !!! bundled emit support, omit bundled refs
// if (tx.isBundledEmit && contains((node as Bundle).sourceFiles, file)) continue
paths := tx.host.GetOutputPathsFor(file, true)
// Try to use output path for referenced file, or output js path if that doesn't exist, or the input path if all else fails
declFileName = paths.DeclarationFilePath()
Expand Down Expand Up @@ -1047,11 +1042,6 @@ func (tx *DeclarationTransformer) rewriteModuleSpecifier(parent *ast.Node, input
return nil
}
tx.resultHasExternalModuleIndicator = tx.resultHasExternalModuleIndicator || (parent.Kind != ast.KindModuleDeclaration && parent.Kind != ast.KindImportType)
if ast.IsStringLiteralLike(input) {
if tx.isBundledEmit {
// !!! TODO: support bundled emit specifier rewriting
}
}
return input
}

Expand Down Expand Up @@ -1578,7 +1568,7 @@ func (tx *DeclarationTransformer) ensureModifierFlags(node *ast.Node) ast.Modifi
additions = ast.ModifierFlagsAmbient
}
parentIsFile := node.Parent.Kind == ast.KindSourceFile
if !parentIsFile || (tx.isBundledEmit && parentIsFile && ast.IsExternalModule(node.Parent.AsSourceFile())) {
if !parentIsFile {
mask ^= ast.ModifierFlagsAmbient
additions = ast.ModifierFlagsNone
}
Expand Down
Loading