@@ -60,14 +60,14 @@ data class EtsImportInfo(
6060 * ```
6161 */
6262 val isDefaultImport: Boolean
63- get() = type == EtsImportType .DEFAULT || originalName == " default "
63+ get() = type == EtsImportType .DEFAULT
6464
6565 /* *
6666 * Whether this is a named import.
6767 *
6868 * ```ts
6969 * import { useState } from 'react';
70- * import { useState as useReactState } from 'react';
70+ * import { Component as ReactComponent } from 'react';
7171 * ```
7272 */
7373 val isNamedImport: Boolean
@@ -81,7 +81,7 @@ data class EtsImportInfo(
8181 * ```
8282 */
8383 val isNamespaceImport: Boolean
84- get() = type == EtsImportType .NAMESPACE || nameBeforeAs == " * "
84+ get() = type == EtsImportType .NAMESPACE
8585
8686 /* *
8787 * Whether this is a side-effect import.
@@ -93,49 +93,28 @@ data class EtsImportInfo(
9393 val isSideEffectImport: Boolean
9494 get() = type == EtsImportType .SIDE_EFFECT
9595
96- /* *
97- * Whether this import uses aliasing.
98- *
99- * ```ts
100- * import { Component as ReactComponent } from 'react';
101- * import { default as React } from 'react';
102- * import React from 'react';
103- * ```
104- */
105- val isAliased: Boolean
106- get() = nameBeforeAs != null && nameBeforeAs != " *" && nameBeforeAs != name
107-
108- override val isDefault: Boolean
109- get() = isDefaultImport || super .isDefault
110-
111- override fun toString (): String = buildString {
112- append(" import " )
113-
114- when {
115- isSideEffectImport -> {
116- // Side effect import: import './styles.css'
117- append(" '$from '" )
118- }
119-
120- isNamespaceImport -> {
121- // Namespace import: import * as Utils from './utils'
122- append(" * as $name from '$from '" )
123- }
124-
125- isAliased -> {
126- // Aliased import: import { Component as ReactComponent } from 'react'
127- append(" { $originalName as $name } from '$from '" )
128- }
129-
130- isNamedImport -> {
131- // Named import: import { useState } from 'react'
132- append(" { $name } from '$from '" )
133- }
134-
135- isDefaultImport -> {
136- // Default import: import React from 'react'
137- append(" $name from '$from '" )
138- }
96+ override fun toString (): String = when (type) {
97+ EtsImportType .DEFAULT -> {
98+ // Default import: import React from 'react'
99+ " import $name from '$from '"
100+ }
101+
102+ EtsImportType .NAMED -> {
103+ // Named import:
104+ // import { useState } from 'react'
105+ // import { Component as ReactComponent } from 'react'
106+ val alias = if (name != originalName) " as $name " else " "
107+ " import { $originalName$alias } from '$from '"
108+ }
109+
110+ EtsImportType .NAMESPACE -> {
111+ // Namespace import: import * as Utils from './utils'
112+ " import * as $name from '$from '"
113+ }
114+
115+ EtsImportType .SIDE_EFFECT -> {
116+ // Side effect import: import './styles.css'
117+ " import '$from '"
139118 }
140119 }
141120}
0 commit comments