Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't re-write import * as ... from ... #1083

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/nodes/ImportDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ export const ImportDirective = {
let document;

if (node.unitAlias) {
// import "./Foo.sol" as Foo;
document = [importPath, ' as ', node.unitAlias];
// First we look for '*' between the beginning of the import and the
// beginning of the importPath
document = options.originalText
.slice(options.locStart(node), options.locStart(node.pathLiteral))
.includes('*')
? // import * as Bar from "./Bar.sol";
['* as ', node.unitAlias, ' from ', importPath]
: // import "./Foo.sol" as Foo;
[importPath, ' as ', node.unitAlias];
} else if (node.symbolAliases) {
// import { Foo, Bar as Qux } from "./Foo.sol";
const compiler = coerce(options.compiler);
Expand Down
4 changes: 2 additions & 2 deletions tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "
=====================================output=====================================
import "SomeFile.sol";
import "SomeFile.sol" as SomeOtherFile;
import "AnotherFile.sol" as SomeSymbol;
import * as SomeSymbol from "AnotherFile.sol";
import { symbol1 as alias1, symbol2 } from "File.sol";
import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from "File2.sol";

Expand All @@ -38,7 +38,7 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "
=====================================output=====================================
import "SomeFile.sol";
import "SomeFile.sol" as SomeOtherFile;
import "AnotherFile.sol" as SomeSymbol;
import * as SomeSymbol from "AnotherFile.sol";
import {symbol1 as alias1, symbol2} from "File.sol";
import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol";

Expand Down
Loading