mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
parent
1facc8d35d
commit
0d7bc8f255
3 changed files with 117 additions and 6 deletions
|
|
@ -171,6 +171,7 @@ pub enum AstKind<'a> {
|
||||||
TSTypeParameter(&'a TSTypeParameter<'a>),
|
TSTypeParameter(&'a TSTypeParameter<'a>),
|
||||||
TSTypeParameterDeclaration(&'a TSTypeParameterDeclaration<'a>),
|
TSTypeParameterDeclaration(&'a TSTypeParameterDeclaration<'a>),
|
||||||
TSTypeParameterInstantiation(&'a TSTypeParameterInstantiation<'a>),
|
TSTypeParameterInstantiation(&'a TSTypeParameterInstantiation<'a>),
|
||||||
|
TSImportType(&'a TSImportType<'a>),
|
||||||
|
|
||||||
TSPropertySignature(&'a TSPropertySignature<'a>),
|
TSPropertySignature(&'a TSPropertySignature<'a>),
|
||||||
}
|
}
|
||||||
|
|
@ -485,6 +486,7 @@ impl<'a> GetSpan for AstKind<'a> {
|
||||||
Self::TSTypeParameter(x) => x.span,
|
Self::TSTypeParameter(x) => x.span,
|
||||||
Self::TSTypeParameterDeclaration(x) => x.span,
|
Self::TSTypeParameterDeclaration(x) => x.span,
|
||||||
Self::TSTypeParameterInstantiation(x) => x.span,
|
Self::TSTypeParameterInstantiation(x) => x.span,
|
||||||
|
Self::TSImportType(x) => x.span,
|
||||||
|
|
||||||
Self::TSPropertySignature(x) => x.span,
|
Self::TSPropertySignature(x) => x.span,
|
||||||
}
|
}
|
||||||
|
|
@ -672,6 +674,7 @@ impl<'a> AstKind<'a> {
|
||||||
Self::TSTypeParameter(_) => "TSTypeParameter".into(),
|
Self::TSTypeParameter(_) => "TSTypeParameter".into(),
|
||||||
Self::TSTypeParameterDeclaration(_) => "TSTypeParameterDeclaration".into(),
|
Self::TSTypeParameterDeclaration(_) => "TSTypeParameterDeclaration".into(),
|
||||||
Self::TSTypeParameterInstantiation(_) => "TSTypeParameterInstantiation".into(),
|
Self::TSTypeParameterInstantiation(_) => "TSTypeParameterInstantiation".into(),
|
||||||
|
Self::TSImportType(_) => "TSImportType".into(),
|
||||||
|
|
||||||
Self::TSPropertySignature(_) => "TSPropertySignature".into(),
|
Self::TSPropertySignature(_) => "TSPropertySignature".into(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -482,7 +482,7 @@ pub trait Visit<'a>: Sized {
|
||||||
ClassElement::MethodDefinition(def) => self.visit_method_definition(def),
|
ClassElement::MethodDefinition(def) => self.visit_method_definition(def),
|
||||||
ClassElement::PropertyDefinition(def) => self.visit_property_definition(def),
|
ClassElement::PropertyDefinition(def) => self.visit_property_definition(def),
|
||||||
ClassElement::AccessorProperty(_def) => { /* TODO */ }
|
ClassElement::AccessorProperty(_def) => { /* TODO */ }
|
||||||
ClassElement::TSIndexSignature(_def) => {}
|
ClassElement::TSIndexSignature(sig) => self.visit_ts_index_signature(sig),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1345,10 +1345,30 @@ pub trait Visit<'a>: Sized {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.visit_string_literal(&decl.source);
|
self.visit_string_literal(&decl.source);
|
||||||
// TODO: assertions
|
if let Some(with_clause) = &decl.with_clause {
|
||||||
|
self.visit_with_clause(with_clause);
|
||||||
|
}
|
||||||
self.leave_node(kind);
|
self.leave_node(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_with_clause(&mut self, with_clause: &WithClause<'a>) {
|
||||||
|
for attribute in &with_clause.with_entries {
|
||||||
|
self.visit_import_attribute(attribute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_import_attribute(&mut self, attribute: &ImportAttribute<'a>) {
|
||||||
|
self.visit_import_attribute_key(&attribute.key);
|
||||||
|
self.visit_string_literal(&attribute.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_import_attribute_key(&mut self, key: &ImportAttributeKey<'a>) {
|
||||||
|
match key {
|
||||||
|
ImportAttributeKey::Identifier(ident) => self.visit_identifier_name(ident),
|
||||||
|
ImportAttributeKey::StringLiteral(ident) => self.visit_string_literal(ident),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_import_declaration_specifier(&mut self, specifier: &ImportDeclarationSpecifier<'a>) {
|
fn visit_import_declaration_specifier(&mut self, specifier: &ImportDeclarationSpecifier<'a>) {
|
||||||
match &specifier {
|
match &specifier {
|
||||||
ImportDeclarationSpecifier::ImportSpecifier(specifier) => {
|
ImportDeclarationSpecifier::ImportSpecifier(specifier) => {
|
||||||
|
|
@ -1876,11 +1896,45 @@ pub trait Visit<'a>: Sized {
|
||||||
self.enter_node(kind);
|
self.enter_node(kind);
|
||||||
match &ty.expr_name {
|
match &ty.expr_name {
|
||||||
TSTypeQueryExprName::TSTypeName(name) => self.visit_ts_type_name(name),
|
TSTypeQueryExprName::TSTypeName(name) => self.visit_ts_type_name(name),
|
||||||
TSTypeQueryExprName::TSImportType(_import) => {} // TODO
|
TSTypeQueryExprName::TSImportType(import) => self.visit_ts_import_type(import),
|
||||||
}
|
}
|
||||||
if let Some(type_parameters) = &ty.type_parameters {
|
if let Some(type_parameters) = &ty.type_parameters {
|
||||||
self.visit_ts_type_parameter_instantiation(type_parameters);
|
self.visit_ts_type_parameter_instantiation(type_parameters);
|
||||||
}
|
}
|
||||||
self.leave_node(kind);
|
self.leave_node(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_ts_import_type(&mut self, ty: &TSImportType<'a>) {
|
||||||
|
let kind = AstKind::TSImportType(self.alloc(ty));
|
||||||
|
self.enter_node(kind);
|
||||||
|
self.visit_ts_type(&ty.argument);
|
||||||
|
if let Some(name) = &ty.qualifier {
|
||||||
|
self.visit_ts_type_name(name);
|
||||||
|
}
|
||||||
|
if let Some(attrs) = &ty.attributes {
|
||||||
|
self.visit_ts_import_attributes(attrs);
|
||||||
|
}
|
||||||
|
if let Some(type_parameter) = &ty.type_parameters {
|
||||||
|
self.visit_ts_type_parameter_instantiation(type_parameter);
|
||||||
|
}
|
||||||
|
self.leave_node(kind);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_ts_import_attributes(&mut self, attributes: &TSImportAttributes<'a>) {
|
||||||
|
for element in &attributes.elements {
|
||||||
|
self.visit_ts_import_attribute(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_ts_import_attribute(&mut self, attribute: &TSImportAttribute<'a>) {
|
||||||
|
self.visit_ts_import_attribute_name(&attribute.name);
|
||||||
|
self.visit_expression(&attribute.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_ts_import_attribute_name(&mut self, name: &TSImportAttributeName<'a>) {
|
||||||
|
match name {
|
||||||
|
TSImportAttributeName::Identifier(ident) => self.visit_identifier_name(ident),
|
||||||
|
TSImportAttributeName::StringLiteral(ident) => self.visit_string_literal(ident),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -482,7 +482,7 @@ pub trait VisitMut<'a>: Sized {
|
||||||
ClassElement::MethodDefinition(def) => self.visit_method_definition(def),
|
ClassElement::MethodDefinition(def) => self.visit_method_definition(def),
|
||||||
ClassElement::PropertyDefinition(def) => self.visit_property_definition(def),
|
ClassElement::PropertyDefinition(def) => self.visit_property_definition(def),
|
||||||
ClassElement::AccessorProperty(_def) => { /* TODO */ }
|
ClassElement::AccessorProperty(_def) => { /* TODO */ }
|
||||||
ClassElement::TSIndexSignature(_def) => {}
|
ClassElement::TSIndexSignature(sig) => self.visit_ts_index_signature(sig),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1339,10 +1339,30 @@ pub trait VisitMut<'a>: Sized {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.visit_string_literal(&mut decl.source);
|
self.visit_string_literal(&mut decl.source);
|
||||||
// TODO: assertions
|
if let Some(with_clause) = &mut decl.with_clause {
|
||||||
|
self.visit_with_clause(with_clause);
|
||||||
|
}
|
||||||
self.leave_node(kind);
|
self.leave_node(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_with_clause(&mut self, with_clause: &mut WithClause<'a>) {
|
||||||
|
for attribute in with_clause.with_entries.iter_mut() {
|
||||||
|
self.visit_import_attribute(attribute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_import_attribute(&mut self, attribute: &mut ImportAttribute<'a>) {
|
||||||
|
self.visit_import_attribute_key(&mut attribute.key);
|
||||||
|
self.visit_string_literal(&mut attribute.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_import_attribute_key(&mut self, key: &mut ImportAttributeKey<'a>) {
|
||||||
|
match key {
|
||||||
|
ImportAttributeKey::Identifier(ident) => self.visit_identifier_name(ident),
|
||||||
|
ImportAttributeKey::StringLiteral(ident) => self.visit_string_literal(ident),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_import_declaration_specifier(
|
fn visit_import_declaration_specifier(
|
||||||
&mut self,
|
&mut self,
|
||||||
specifier: &mut ImportDeclarationSpecifier<'a>,
|
specifier: &mut ImportDeclarationSpecifier<'a>,
|
||||||
|
|
@ -1878,11 +1898,45 @@ pub trait VisitMut<'a>: Sized {
|
||||||
self.enter_node(kind);
|
self.enter_node(kind);
|
||||||
match &mut ty.expr_name {
|
match &mut ty.expr_name {
|
||||||
TSTypeQueryExprName::TSTypeName(name) => self.visit_ts_type_name(name),
|
TSTypeQueryExprName::TSTypeName(name) => self.visit_ts_type_name(name),
|
||||||
TSTypeQueryExprName::TSImportType(_import) => {} // TODO
|
TSTypeQueryExprName::TSImportType(import) => self.visit_ts_import_type(import),
|
||||||
}
|
}
|
||||||
if let Some(type_parameters) = &mut ty.type_parameters {
|
if let Some(type_parameters) = &mut ty.type_parameters {
|
||||||
self.visit_ts_type_parameter_instantiation(type_parameters);
|
self.visit_ts_type_parameter_instantiation(type_parameters);
|
||||||
}
|
}
|
||||||
self.leave_node(kind);
|
self.leave_node(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_ts_import_type(&mut self, ty: &mut TSImportType<'a>) {
|
||||||
|
let kind = AstKind::TSImportType(self.alloc(ty));
|
||||||
|
self.enter_node(kind);
|
||||||
|
self.visit_ts_type(&mut ty.argument);
|
||||||
|
if let Some(name) = &mut ty.qualifier {
|
||||||
|
self.visit_ts_type_name(name);
|
||||||
|
}
|
||||||
|
if let Some(attrs) = &mut ty.attributes {
|
||||||
|
self.visit_ts_import_attributes(attrs);
|
||||||
|
}
|
||||||
|
if let Some(type_parameter) = &mut ty.type_parameters {
|
||||||
|
self.visit_ts_type_parameter_instantiation(type_parameter);
|
||||||
|
}
|
||||||
|
self.leave_node(kind);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_ts_import_attributes(&mut self, attributes: &mut TSImportAttributes<'a>) {
|
||||||
|
for element in attributes.elements.iter_mut() {
|
||||||
|
self.visit_ts_import_attribute(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_ts_import_attribute(&mut self, attribute: &mut TSImportAttribute<'a>) {
|
||||||
|
self.visit_ts_import_attribute_name(&mut attribute.name);
|
||||||
|
self.visit_expression(&mut attribute.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_ts_import_attribute_name(&mut self, name: &mut TSImportAttributeName<'a>) {
|
||||||
|
match name {
|
||||||
|
TSImportAttributeName::Identifier(ident) => self.visit_identifier_name(ident),
|
||||||
|
TSImportAttributeName::StringLiteral(ident) => self.visit_string_literal(ident),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue