Skip to content
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 2 additions & 0 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const { values: options } = parseArgs({
args: process.argv.slice(2),
options: {
race: { type: "boolean" },
tests: { type: "string", short: "t" },
fix: { type: "boolean" },
noembed: { type: "boolean" },
debug: { type: "boolean" },
Expand Down Expand Up @@ -203,6 +204,7 @@ export const generate = task({
const goTestFlags = [
...goBuildFlags,
...goBuildTags(),
...(options.tests ? [`-run=${options.tests}`] : []),
];

const goTestEnv = {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tsgo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func main() {
var emitTime time.Duration
if compilerOptions.NoEmit.IsFalseOrUnknown() {
emitStart := time.Now()
result := program.Emit(&ts.EmitOptions{})
result := program.Emit(ts.EmitOptions{})
diagnostics = append(diagnostics, result.Diagnostics...)
emitTime = time.Since(emitStart)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ func GetExternalModuleName(node *Node) *Expression {
case KindImportType:
return getImportTypeNodeLiteral(node)
case KindCallExpression:
return node.AsCallExpression().Arguments.Nodes[0]
return core.FirstOrNil(node.AsCallExpression().Arguments.Nodes)
case KindModuleDeclaration:
if IsStringLiteral(node.AsModuleDeclaration().Name()) {
return node.AsModuleDeclaration().Name()
Expand Down
23 changes: 13 additions & 10 deletions internal/ast/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,21 @@ func (v *NodeVisitor) visitTopLevelStatements(nodes *StatementList) *StatementLi
}

func (v *NodeVisitor) liftToBlock(node *Statement) *Statement {
if node != nil && node.Kind == KindSyntaxList {
nodes := node.AsSyntaxList().Children
if len(nodes) == 0 {
node = nil
} else if len(nodes) == 1 {
node = nodes[0]
var nodes []*Node
if node != nil {
if node.Kind == KindSyntaxList {
nodes = node.AsSyntaxList().Children
} else {
node = v.Factory.NewBlock(v.Factory.NewNodeList(nodes), true /*multiLine*/)
}
if node != nil && node.Kind == KindSyntaxList {
panic("The result of visiting and lifting a Node may not be SyntaxList")
nodes = []*Node{node}
}
}
if len(nodes) == 1 {
node = nodes[0]
} else {
node = v.Factory.NewBlock(v.Factory.NewNodeList(nodes), true /*multiLine*/)
}
if node.Kind == KindSyntaxList {
panic("The result of visiting and lifting a Node may not be SyntaxList")
}
return node
}
10 changes: 7 additions & 3 deletions internal/binder/referenceresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ var _ ReferenceResolver = &referenceResolver{}

type referenceResolver struct {
resolver *NameResolver
options *core.CompilerOptions
hooks ReferenceResolverHooks
}

func NewReferenceResolver(hooks ReferenceResolverHooks) ReferenceResolver {
func NewReferenceResolver(options *core.CompilerOptions, hooks ReferenceResolverHooks) ReferenceResolver {
return &referenceResolver{
hooks: hooks,
options: options,
hooks: hooks,
}
}

Expand Down Expand Up @@ -91,7 +93,9 @@ func (r *referenceResolver) getReferencedValueSymbol(reference *ast.IdentifierNo
}

if r.resolver == nil {
r.resolver = &NameResolver{}
r.resolver = &NameResolver{
CompilerOptions: r.options,
}
}

return r.resolver.Resolve(location, reference.Text(), ast.SymbolFlagsExportValue|ast.SymbolFlagsValue|ast.SymbolFlagsAlias, nil /*nameNotFoundMessage*/, false /*isUse*/, false /*excludeGlobals*/)
Expand Down
4 changes: 2 additions & 2 deletions internal/checker/emitresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (r *emitResolver) isValueAliasDeclarationWorker(node *ast.Node) bool {
core.Some(exportClause.AsNamedExports().Elements.Nodes, r.isValueAliasDeclaration))
case ast.KindExportAssignment:
if node.AsExportAssignment().Expression != nil && node.AsExportAssignment().Expression.Kind == ast.KindIdentifier {
return r.isAliasResolvedToValue(c.getSymbolOfDeclaration(node) /*excludeTypeOnlyValues*/, true)
return r.isAliasResolvedToValue(c.getSymbolOfDeclaration(node), true /*excludeTypeOnlyValues*/)
}
return true
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func (r *emitResolver) GetExternalModuleFileFromDeclaration(node *ast.Node) *ast

func (r *emitResolver) getReferenceResolver() binder.ReferenceResolver {
if r.referenceResolver == nil {
r.referenceResolver = binder.NewReferenceResolver(binder.ReferenceResolverHooks{
r.referenceResolver = binder.NewReferenceResolver(r.checker.compilerOptions, binder.ReferenceResolverHooks{
ResolveName: r.checker.resolveName,
GetResolvedSymbol: r.checker.getResolvedSymbol,
GetMergedSymbol: r.checker.getMergedSymbol,
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (e *emitter) getScriptTransformers(emitContext *printer.EmitContext, source
emitResolver.MarkLinkedReferencesRecursively(sourceFile)
referenceResolver = emitResolver
} else {
referenceResolver = binder.NewReferenceResolver(binder.ReferenceResolverHooks{})
referenceResolver = binder.NewReferenceResolver(options, binder.ReferenceResolverHooks{})
}

// erase types
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ type sourceMapEmitResult struct {
sourceMap *sourcemap.RawSourceMap
}

func (p *Program) Emit(options *EmitOptions) *EmitResult {
func (p *Program) Emit(options EmitOptions) *EmitResult {
// !!! performance measurement
p.BindSourceFiles()

Expand Down
2 changes: 1 addition & 1 deletion internal/execute/tsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func compileAndEmit(sys System, program *compiler.Program, reportDiagnostic diag
emitResult := &compiler.EmitResult{EmitSkipped: true, Diagnostics: []*ast.Diagnostic{}}
if !options.ListFilesOnly.IsTrue() {
// !!! Emit is not yet fully implemented, will not emit unless `outfile` specified
emitResult = program.Emit(&compiler.EmitOptions{})
emitResult = program.Emit(compiler.EmitOptions{})
}
diagnostics = append(diagnostics, emitResult.Diagnostics...)

Expand Down
42 changes: 37 additions & 5 deletions internal/testrunner/compiler_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ func (r *CompilerBaselineRunner) EnumerateTestFiles() []string {
func (r *CompilerBaselineRunner) RunTests(t *testing.T) {
r.cleanUpLocal(t)
files := r.EnumerateTestFiles()
skippedTests := []string{
"mappedTypeRecursiveInference.ts", // Needed until we have type printer with truncation limit.
skippedTests := map[string]string{
"mappedTypeRecursiveInference.ts": "Skipped until we have type printer with truncation limit.",
"jsFileCompilationWithoutJsExtensions.ts": "Skipped until we have proper allowJS support (and errors when not enabled.)",
"fileReferencesWithNoExtensions.ts": "Skipped until we support adding missing extensions in subtasks in fileloader.go",
"typeOnlyMerge2.ts": "Needs investigation",
"typeOnlyMerge3.ts": "Needs investigation",
"filesEmittingIntoSameOutput.ts": "Output order nondeterministic due to collision on filename during parallel emit.",
}
deprecatedTests := []string{
// Test deprecated `importsNotUsedAsValue`
Expand All @@ -100,7 +105,8 @@ func (r *CompilerBaselineRunner) RunTests(t *testing.T) {
"importsNotUsedAsValues_error.ts",
}
for _, filename := range files {
if slices.Contains(skippedTests, tspath.GetBaseFileName(filename)) {
if msg, ok := skippedTests[tspath.GetBaseFileName(filename)]; ok {
t.Run(tspath.GetBaseFileName(filename), func(t *testing.T) { t.Skip(msg) })
continue
}
if slices.Contains(deprecatedTests, tspath.GetBaseFileName(filename)) {
Expand Down Expand Up @@ -174,6 +180,7 @@ func (r *CompilerBaselineRunner) runSingleConfigTest(t *testing.T, testName stri
compilerTest := newCompilerTest(t, testName, test.filename, &payload, config)

compilerTest.verifyDiagnostics(t, r.testSuitName, r.isSubmodule)
compilerTest.verifyJavaScriptOutput(t, r.testSuitName, r.isSubmodule)
compilerTest.verifyTypesAndSymbols(t, r.testSuitName, r.isSubmodule)
// !!! Verify all baselines
}
Expand Down Expand Up @@ -325,8 +332,6 @@ var concurrentSkippedErrorBaselines = core.NewSetFromItems(
"recursiveExportAssignmentAndFindAliasedType2.ts",
"recursiveExportAssignmentAndFindAliasedType3.ts",
"superInStaticMembers1.ts target=es2015",
"typeOnlyMerge2.ts",
"typeOnlyMerge3.ts",
)

func (c *compilerTest) verifyDiagnostics(t *testing.T, suiteName string, isSubmodule bool) {
Expand All @@ -341,6 +346,33 @@ func (c *compilerTest) verifyDiagnostics(t *testing.T, suiteName string, isSubmo
})
}

func (c *compilerTest) verifyJavaScriptOutput(t *testing.T, suiteName string, isSubmodule bool) {
if !c.hasNonDtsFiles {
return
}

t.Run("output", func(t *testing.T) {
defer testutil.RecoverAndFail(t, "Panic on creating js output for test "+c.filename)
headerComponents := tspath.GetPathComponentsRelativeTo(repo.TestDataPath, c.filename, tspath.ComparePathsOptions{})
if isSubmodule {
headerComponents = headerComponents[4:] // Strip "./../_submodules/TypeScript" prefix
}
header := tspath.GetPathFromPathComponents(headerComponents)
tsbaseline.DoJsEmitBaseline(
t,
c.configuredName,
header,
c.options,
c.result,
c.tsConfigFiles,
c.toBeCompiled,
c.otherFiles,
c.harnessOptions,
baseline.Options{Subfolder: suiteName, IsSubmodule: isSubmodule},
)
})
}

func (c *compilerTest) verifyTypesAndSymbols(t *testing.T, suiteName string, isSubmodule bool) {
noTypesAndSymbols := c.harnessOptions.NoTypesAndSymbols
if noTypesAndSymbols {
Expand Down
Loading