Skip to content

Commit

Permalink
chore(copybara): sync commits from Aspect-internal silo (#485)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Bedard <[email protected]>
  • Loading branch information
gregmagolan and jbedard authored Jun 30, 2023
1 parent 6abb4bf commit 2d6d8cb
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion gazelle/js/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (ts *typeScriptLang) addProjectRule(cfg *JsGazelleConfig, args language.Gen
if len(result.Errors) > 0 {
fmt.Printf("%s:\n", result.SourcePath)
for _, err := range result.Errors {
fmt.Printf("\t%s\n", err)
fmt.Printf("%s\n", err)
}
fmt.Println()
}
Expand Down
8 changes: 0 additions & 8 deletions gazelle/js/parser/tests/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,6 @@ func RunParserTests(t *testing.T, parser parser.Parser, includeTypeOnly bool, pa
}
})
}

t.Run("invalid syntax"+parserPost, func(t *testing.T) {
_, errs := parser.ParseImports("bad-syntax.ts", "bad syntax")

if len(errs) == 0 {
t.Error("Invalid syntax should return errors")
}
})
}

func equal[T comparable](a, b []T) bool {
Expand Down
10 changes: 7 additions & 3 deletions gazelle/js/parser/treesitter/parser_treesitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ func (p *TreeSitterParser) ParseImports(filePath, sourceCodeStr string) ([]strin
imports = append(imports, queryResults...)
}

treeErrors := treeutils.QueryErrors(sourceLangName, sourceLang, sourceCode, rootNode)
if treeErrors != nil {
errs = append(errs, treeErrors...)
// Parse errors. Only log them due to many false positives potentially caused by issues
// such as only parsing a single file at a time so type information from other files is missing.
if Log.IsLevelEnabled(logrus.TraceLevel) {
treeErrors := treeutils.QueryErrors(sourceLangName, sourceLang, sourceCode, rootNode)
if treeErrors != nil {
Log.Tracef("TreeSitter query errors: %v", treeErrors)
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions gazelle/js/tests/parse_errors/BUILD.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# gazelle:js_ignore_imports mystery-module
# gazelle:js_ignore_imports unknown-library
4 changes: 4 additions & 0 deletions gazelle/js/tests/parse_errors/BUILD.out
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

# gazelle:js_ignore_imports mystery-module
# gazelle:js_ignore_imports unknown-library

ts_project(
name = "parse_errors",
srcs = [
"bad.ts",
"globals.d.ts",
"good.ts",
],
)
12 changes: 0 additions & 12 deletions gazelle/js/tests/parse_errors/expectedStdout.txt
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
subbuild/subbuild-bad.ts:
4: bad
^

subdir/subdir-bad.ts:
3: bad SyntaxError on line 3()
^

bad.ts:
2: looks like some bad syntax here
^

13 changes: 13 additions & 0 deletions gazelle/js/tests/parse_errors/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare module '*.module.css' {
const classes: { readonly [key: string]: string }
export default classes
}

export type { I1 } from 'mystery-module'
export { numberFunc } from 'unknown-library'
export interface I2 {}

export interface CreatePreloadedQueryResult<D extends object, V extends I1> {
queryLoader: (variables: V) => Promise<Record<string, I2 | undefined>>
usePreloadedQueryData: () => ReturnType<typeof numberFunc>
}

0 comments on commit 2d6d8cb

Please sign in to comment.