mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(semantic): transform checker do not output spans in errors (#5260)
Transform checker don't output spans in errors. They're inaccurate because (a) spans refer to the source text pre-transform, and (b) most errors relate to scopes/symbols/references newly created in transformer, which have no span.
This commit is contained in:
parent
af5713e411
commit
10861096e0
3 changed files with 10 additions and 2070 deletions
|
|
@ -96,9 +96,9 @@ use rustc_hash::FxHasher;
|
|||
|
||||
use oxc_allocator::{Allocator, CloneIn};
|
||||
#[allow(clippy::wildcard_imports)]
|
||||
use oxc_ast::{ast::*, ast_kind::AstKind, visit::walk, Visit};
|
||||
use oxc_ast::{ast::*, visit::walk, Visit};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_span::{CompactStr, GetSpan};
|
||||
use oxc_span::CompactStr;
|
||||
use oxc_syntax::{
|
||||
reference::ReferenceId,
|
||||
scope::{ScopeFlags, ScopeId},
|
||||
|
|
@ -271,10 +271,6 @@ impl Errors {
|
|||
self.0.push(OxcDiagnostic::error(message.as_ref().trim().to_string()));
|
||||
}
|
||||
|
||||
fn push_with_label<S: Into<String>>(&mut self, message: S, span: Span) {
|
||||
self.0.push(OxcDiagnostic::error(message.into()).with_label(span));
|
||||
}
|
||||
|
||||
/// Add an error for a mismatch between a pair of values, with IDs
|
||||
fn push_mismatch<Id, Ids, Value, Values>(&mut self, title: &str, ids: Ids, values: Values)
|
||||
where
|
||||
|
|
@ -556,24 +552,23 @@ impl<'s> PostTransformChecker<'s> {
|
|||
/// Collector of `ScopeId`s, `SymbolId`s and `ReferenceId`s from an AST.
|
||||
///
|
||||
/// `scope_ids`, `symbol_ids` and `reference_ids` lists are filled in visitation order.
|
||||
struct SemanticIdsCollector<'a, 'e> {
|
||||
struct SemanticIdsCollector<'e> {
|
||||
scope_ids: Vec<Option<ScopeId>>,
|
||||
symbol_ids: Vec<Option<SymbolId>>,
|
||||
reference_ids: Vec<Option<ReferenceId>>,
|
||||
kinds: Vec<AstKind<'a>>,
|
||||
errors: &'e mut Errors,
|
||||
}
|
||||
|
||||
impl<'a, 'e> SemanticIdsCollector<'a, 'e> {
|
||||
impl<'e> SemanticIdsCollector<'e> {
|
||||
fn new(errors: &'e mut Errors) -> Self {
|
||||
Self { scope_ids: vec![], symbol_ids: vec![], reference_ids: vec![], kinds: vec![], errors }
|
||||
Self { scope_ids: vec![], symbol_ids: vec![], reference_ids: vec![], errors }
|
||||
}
|
||||
|
||||
/// Collect IDs and check for errors
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn collect(
|
||||
mut self,
|
||||
program: &Program<'a>,
|
||||
program: &Program<'_>,
|
||||
) -> (Vec<Option<ScopeId>>, Vec<Option<SymbolId>>, Vec<Option<ReferenceId>>) {
|
||||
if !program.source_type.is_typescript_definition() {
|
||||
self.visit_program(program);
|
||||
|
|
@ -582,20 +577,12 @@ impl<'a, 'e> SemanticIdsCollector<'a, 'e> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'e> Visit<'a> for SemanticIdsCollector<'a, 'e> {
|
||||
fn enter_node(&mut self, kind: AstKind<'a>) {
|
||||
self.kinds.push(kind);
|
||||
}
|
||||
|
||||
fn leave_node(&mut self, _kind: AstKind<'a>) {
|
||||
self.kinds.pop();
|
||||
}
|
||||
|
||||
impl<'a, 'e> Visit<'a> for SemanticIdsCollector<'e> {
|
||||
fn enter_scope(&mut self, _flags: ScopeFlags, scope_id: &Cell<Option<ScopeId>>) {
|
||||
let scope_id = scope_id.get();
|
||||
self.scope_ids.push(scope_id);
|
||||
if scope_id.is_none() {
|
||||
self.errors.push_with_label("Missing ScopeId", self.kinds.last().unwrap().span());
|
||||
self.errors.push("Missing ScopeId");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -603,7 +590,7 @@ impl<'a, 'e> Visit<'a> for SemanticIdsCollector<'a, 'e> {
|
|||
let reference_id = ident.reference_id.get();
|
||||
self.reference_ids.push(reference_id);
|
||||
if reference_id.is_none() {
|
||||
self.errors.push_with_label(format!("Missing ReferenceId: {}", ident.name), ident.span);
|
||||
self.errors.push(format!("Missing ReferenceId: {}", ident.name));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -611,7 +598,7 @@ impl<'a, 'e> Visit<'a> for SemanticIdsCollector<'a, 'e> {
|
|||
let symbol_id = ident.symbol_id.get();
|
||||
self.symbol_ids.push(symbol_id);
|
||||
if symbol_id.is_none() {
|
||||
self.errors.push_with_label(format!("Missing SymbolId: {}", ident.name), ident.span);
|
||||
self.errors.push(format!("Missing SymbolId: {}", ident.name));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -10,32 +10,12 @@ Passed: 10/36
|
|||
# babel-plugin-transform-typescript (2/7)
|
||||
* computed-constant-value/input.ts
|
||||
x Missing ReferenceId: Infinity
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/computed-constant-value/input.ts:1:1]
|
||||
1 | enum A {
|
||||
: ^
|
||||
2 | a = Infinity,
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: Infinity
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/computed-constant-value/input.ts:1:1]
|
||||
1 | enum A {
|
||||
: ^
|
||||
2 | a = Infinity,
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: Infinity
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/computed-constant-value/input.ts:1:1]
|
||||
1 | enum A {
|
||||
: ^
|
||||
2 | a = Infinity,
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: Infinity
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/computed-constant-value/input.ts:1:1]
|
||||
1 | enum A {
|
||||
: ^
|
||||
2 | a = Infinity,
|
||||
`----
|
||||
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["A", "a", "b", "c", "d", "e"]
|
||||
|
|
@ -104,11 +84,6 @@ Passed: 10/36
|
|||
|
||||
* enum-member-reference/input.ts
|
||||
x Missing ReferenceId: Foo
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/enum-member-reference/input.ts:1:1]
|
||||
1 | var x = 10;
|
||||
: ^
|
||||
2 |
|
||||
`----
|
||||
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["Foo", "a", "b", "c"]
|
||||
|
|
@ -133,39 +108,14 @@ Passed: 10/36
|
|||
|
||||
* export-elimination/input.ts
|
||||
x Missing SymbolId: Name
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/export-elimination/input.ts:1:1]
|
||||
1 | import Im, {Ok} from 'a';
|
||||
: ^
|
||||
2 | class Foo {}
|
||||
`----
|
||||
|
||||
x Missing SymbolId: _Name
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/export-elimination/input.ts:1:1]
|
||||
1 | import Im, {Ok} from 'a';
|
||||
: ^
|
||||
2 | class Foo {}
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: _Name
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/export-elimination/input.ts:1:1]
|
||||
1 | import Im, {Ok} from 'a';
|
||||
: ^
|
||||
2 | class Foo {}
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: Name
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/export-elimination/input.ts:1:1]
|
||||
1 | import Im, {Ok} from 'a';
|
||||
: ^
|
||||
2 | class Foo {}
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: Name
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/export-elimination/input.ts:1:1]
|
||||
1 | import Im, {Ok} from 'a';
|
||||
: ^
|
||||
2 | class Foo {}
|
||||
`----
|
||||
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(0): ["Baq", "Bar", "Baz", "Foo", "Func", "Im",
|
||||
|
|
@ -557,11 +507,6 @@ Passed: 10/36
|
|||
|
||||
* refresh/generates-valid-signature-for-exotic-ways-to-call-hooks/input.jsx
|
||||
x Missing ScopeId
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-valid-signature-for-exotic-ways-to-call-hooks/input.jsx:1:1]
|
||||
1 | import FancyHook from 'fancy';
|
||||
: ^
|
||||
2 |
|
||||
`----
|
||||
|
||||
x Symbol reference IDs mismatch:
|
||||
| after transform: SymbolId(10): [ReferenceId(17), ReferenceId(18),
|
||||
|
|
@ -598,18 +543,8 @@ Passed: 10/36
|
|||
|
||||
* refresh/includes-custom-hooks-into-the-signatures/input.jsx
|
||||
x Missing ScopeId
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures/input.jsx:1:1]
|
||||
1 | function useFancyState() {
|
||||
: ^
|
||||
2 | const [foo, setFoo] = React.useState(0);
|
||||
`----
|
||||
|
||||
x Missing ScopeId
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures/input.jsx:1:1]
|
||||
1 | function useFancyState() {
|
||||
: ^
|
||||
2 | const [foo, setFoo] = React.useState(0);
|
||||
`----
|
||||
|
||||
x Symbol reference IDs mismatch:
|
||||
| after transform: SymbolId(8): [ReferenceId(10), ReferenceId(11),
|
||||
|
|
@ -1222,144 +1157,44 @@ Passed: 10/36
|
|||
* refresh/supports-typescript-namespace-syntax/input.tsx
|
||||
x Output mismatch
|
||||
x Missing SymbolId: Foo
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing SymbolId: _Foo
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing SymbolId: Bar
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing SymbolId: _Bar
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: _Bar
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: _Bar
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: Bar
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: Bar
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: _Foo
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: _Foo
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: _Foo
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: _Foo
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: D
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing SymbolId: NotExported
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing SymbolId: _NotExported
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: _NotExported
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: NotExported
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: NotExported
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: Foo
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Missing ReferenceId: Foo
|
||||
,-[tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx:1:1]
|
||||
1 | namespace Foo {
|
||||
: ^
|
||||
2 | export namespace Bar {
|
||||
`----
|
||||
|
||||
x Binding symbols mismatch:
|
||||
| after transform: ScopeId(0): [SymbolId(0)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue