@@ -293,12 +293,12 @@ export class JavaScriptParserVisitor {
293293 | ts . FunctionDeclaration | ts . ParameterDeclaration | ts . MethodDeclaration | ts . EnumDeclaration | ts . InterfaceDeclaration
294294 | ts . PropertySignature | ts . ConstructorDeclaration | ts . ModuleDeclaration | ts . GetAccessorDeclaration | ts . SetAccessorDeclaration
295295 | ts . ArrowFunction | ts . IndexSignatureDeclaration | ts . TypeAliasDeclaration | ts . ExportDeclaration | ts . ExportAssignment | ts . FunctionExpression
296- | ts . ConstructorTypeNode | ts . TypeParameterDeclaration ) {
296+ | ts . ConstructorTypeNode | ts . TypeParameterDeclaration | ts . ImportDeclaration | ts . ImportEqualsDeclaration ) {
297297 if ( ts . isVariableStatement ( node ) || ts . isModuleDeclaration ( node ) || ts . isClassDeclaration ( node ) || ts . isEnumDeclaration ( node )
298298 || ts . isInterfaceDeclaration ( node ) || ts . isPropertyDeclaration ( node ) || ts . isPropertySignature ( node ) || ts . isParameter ( node )
299299 || ts . isMethodDeclaration ( node ) || ts . isConstructorDeclaration ( node ) || ts . isArrowFunction ( node )
300300 || ts . isIndexSignatureDeclaration ( node ) || ts . isTypeAliasDeclaration ( node ) || ts . isExportDeclaration ( node )
301- || ts . isFunctionDeclaration ( node ) || ts . isFunctionExpression ( node ) || ts . isConstructorTypeNode ( node ) || ts . isTypeParameterDeclaration ( node ) ) {
301+ || ts . isFunctionDeclaration ( node ) || ts . isFunctionExpression ( node ) || ts . isConstructorTypeNode ( node ) || ts . isTypeParameterDeclaration ( node ) || ts . isImportDeclaration ( node ) || ts . isImportEqualsDeclaration ( node ) ) {
302302 return node . modifiers ? node . modifiers ?. filter ( ts . isModifier ) . map ( this . mapModifier ) : [ ] ;
303303 }
304304 else if ( ts . isExportAssignment ( node ) ) {
@@ -3214,7 +3214,46 @@ export class JavaScriptParserVisitor {
32143214 }
32153215
32163216 visitImportEqualsDeclaration ( node : ts . ImportEqualsDeclaration ) {
3217- return this . visitUnknown ( node ) ;
3217+ const kind = this . findChildNode ( node , ts . SyntaxKind . ImportKeyword ) ! ;
3218+
3219+ return new JS . ScopedVariableDeclarations (
3220+ randomId ( ) ,
3221+ this . prefix ( node ) ,
3222+ Markers . EMPTY ,
3223+ this . mapModifiers ( node ) ,
3224+ this . leftPadded (
3225+ this . prefix ( kind ) ,
3226+ JS . ScopedVariableDeclarations . Scope . Import
3227+ ) ,
3228+ [
3229+ this . rightPadded ( new J . VariableDeclarations (
3230+ randomId ( ) ,
3231+ Space . EMPTY ,
3232+ Markers . EMPTY ,
3233+ [ ] ,
3234+ node . isTypeOnly ? [ new J . Modifier (
3235+ randomId ( ) ,
3236+ this . prefix ( this . findChildNode ( node , ts . SyntaxKind . TypeKeyword ) ! ) ,
3237+ Markers . EMPTY ,
3238+ "type" ,
3239+ J . Modifier . Type . LanguageExtension ,
3240+ [ ]
3241+ ) ] : [ ] ,
3242+ null ,
3243+ null ,
3244+ [ ] ,
3245+ [ this . rightPadded ( new J . VariableDeclarations . NamedVariable (
3246+ randomId ( ) ,
3247+ Space . EMPTY ,
3248+ Markers . EMPTY ,
3249+ this . visit ( node . name ) ,
3250+ [ ] ,
3251+ this . leftPadded ( this . suffix ( node . name ) , this . visit ( node . moduleReference ) ) ,
3252+ this . mapVariableType ( node )
3253+ ) , Space . EMPTY ) ]
3254+ ) , Space . EMPTY )
3255+ ]
3256+ )
32183257 }
32193258
32203259 visitImportKeyword ( node : ts . ImportExpression ) {
@@ -3223,46 +3262,46 @@ export class JavaScriptParserVisitor {
32233262 }
32243263
32253264 visitImportDeclaration ( node : ts . ImportDeclaration ) {
3226- const children = node . getChildren ( this . sourceFile ) ;
3227- const _default = ! ! node . importClause ?. name ;
3228- const onlyDefault = _default && node . importClause . namedBindings == undefined ;
32293265 return new JS . JsImport (
32303266 randomId ( ) ,
32313267 this . prefix ( node ) ,
32323268 Markers . EMPTY ,
3233- _default ? this . rightPadded ( this . visit ( node . importClause ?. name ) , this . suffix ( node . importClause ?. name ) ) : null ,
3234- node . importClause ?. isTypeOnly ? this . leftPadded ( this . prefix ( this . findChildNode ( node . importClause , ts . SyntaxKind . TypeKeyword ) ! ) , node . importClause . isTypeOnly ) : this . leftPadded ( Space . EMPTY , false ) ,
3235- node . importClause && ! onlyDefault ? this . visit ( node . importClause ) : null ,
3236- children [ children . indexOf ( node . moduleSpecifier ) - 1 ] . kind == ts . SyntaxKind . FromKeyword ? this . prefix ( children [ children . indexOf ( node . moduleSpecifier ) - 1 ] ) : null ,
3237- this . convert < J . Literal > ( node . moduleSpecifier ) ,
3238- null
3269+ this . mapModifiers ( node ) ,
3270+ node . importClause ? this . visit ( node . importClause ) : null ,
3271+ this . leftPadded ( node . importClause ? this . prefix ( this . findChildNode ( node , ts . SyntaxKind . FromKeyword ) ! ) : Space . EMPTY , this . visit ( node . moduleSpecifier ) ) ,
3272+ node . attributes ? this . visit ( node . attributes ) : null
32393273 ) ;
32403274 }
32413275
32423276 visitImportClause ( node : ts . ImportClause ) {
3243- if ( node . namedBindings && ts . isNamespaceImport ( node . namedBindings ) ) {
3244- return new JContainer (
3245- this . prefix ( node ) ,
3246- [ this . rightPadded ( new JS . Alias (
3247- randomId ( ) ,
3248- Space . EMPTY ,
3249- Markers . EMPTY ,
3250- // this.rightPadded(node.isTypeOnly, node.isTypeOnly ? this.suffix(this.findChildNode(node, ts.SyntaxKind.TypeKeyword)!) : Space.EMPTY),
3251- this . rightPadded ( this . mapIdentifier ( node . namedBindings , "*" ) , this . prefix ( node . namedBindings . getChildAt ( 1 , this . sourceFile ) ) ) ,
3252- this . convert ( node . namedBindings . name )
3253- ) , Space . EMPTY ) ] ,
3254- Markers . EMPTY
3255- ) ;
3256- }
3257- return this . mapCommaSeparatedList ( node . namedBindings ?. getChildren ( this . sourceFile ) ! ) ;
3277+ return new JS . JsImportClause (
3278+ randomId ( ) ,
3279+ this . prefix ( node ) ,
3280+ Markers . EMPTY ,
3281+ node . isTypeOnly ,
3282+ node . name ? this . rightPadded ( this . visit ( node . name ) , this . suffix ( node . name ) ) : null ,
3283+ node . namedBindings ? this . visit ( node . namedBindings ) : null
3284+ ) ;
32583285 }
32593286
32603287 visitNamespaceImport ( node : ts . NamespaceImport ) {
3261- return this . visitUnknown ( node ) ;
3288+ return new JS . Alias (
3289+ randomId ( ) ,
3290+ this . prefix ( node ) ,
3291+ Markers . EMPTY ,
3292+ this . rightPadded ( this . mapIdentifier ( node , "*" ) , this . prefix ( this . findChildNode ( node , ts . SyntaxKind . AsKeyword ) ! ) ) ,
3293+ this . visit ( node . name )
3294+ ) ;
32623295 }
32633296
32643297 visitNamedImports ( node : ts . NamedImports ) {
3265- return this . visitUnknown ( node ) ;
3298+ return new JS . NamedImports (
3299+ randomId ( ) ,
3300+ this . prefix ( node ) ,
3301+ Markers . EMPTY ,
3302+ this . mapCommaSeparatedList ( node . getChildren ( this . sourceFile ) ) ,
3303+ null
3304+ ) ;
32663305 }
32673306
32683307 visitImportSpecifier ( node : ts . ImportSpecifier ) {
@@ -3514,11 +3553,25 @@ export class JavaScriptParserVisitor {
35143553 }
35153554
35163555 visitImportAttributes ( node : ts . ImportAttributes ) {
3517- return this . visitUnknown ( node ) ;
3556+ const openBraceIndex = node . getChildren ( ) . findIndex ( n => n . kind === ts . SyntaxKind . OpenBraceToken ) ;
3557+ const elements = this . mapCommaSeparatedList < JS . ImportAttribute > ( node . getChildren ( this . sourceFile ) . slice ( openBraceIndex , openBraceIndex + 3 ) ) ;
3558+ return new JS . ImportAttributes (
3559+ randomId ( ) ,
3560+ this . prefix ( node ) ,
3561+ Markers . EMPTY ,
3562+ ts . SyntaxKind . WithKeyword === node . token ? JS . ImportAttributes . Token . With : JS . ImportAttributes . Token . Assert ,
3563+ elements
3564+ ) ;
35183565 }
35193566
35203567 visitImportAttribute ( node : ts . ImportAttribute ) {
3521- return this . visitUnknown ( node ) ;
3568+ return new JS . ImportAttribute (
3569+ randomId ( ) ,
3570+ this . prefix ( node ) ,
3571+ Markers . EMPTY ,
3572+ this . visit ( node . name ) ,
3573+ this . leftPadded ( this . suffix ( node . name ) , this . visit ( node . value ) )
3574+ ) ;
35223575 }
35233576
35243577 visitPropertyAssignment ( node : ts . PropertyAssignment ) {
0 commit comments