Skip to content

Commit

Permalink
feature: goldstein: Import: identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed May 27, 2024
1 parent ba49d97 commit 1554718
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,18 @@ Will be converted to:
import hello from './hello.js';
```

Also, also supported:

```gs
import hello from hello;
```

And will be converted to:

```js
import hello from 'hello';
```

### `FunctionDeclaration` with `Arrow`

If you mistakenly put `=>` in function declaration:
Expand Down
1 change: 1 addition & 0 deletions packages/keyword-import/fixture/import-identifier.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import f from hello;
1 change: 1 addition & 0 deletions packages/keyword-import/fixture/import-identifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import f from 'hello';
10 changes: 9 additions & 1 deletion packages/keyword-import/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ export default function keywordImport(Parser) {
node.specifiers = this.parseImportSpecifiers();
this.expectContextual('from');

node.source = this.type === tokTypes.string ? this.parseLiteral(this.value) : this.unexpected();
if (this.type === tokTypes.string)
node.source = this.parseLiteral(this.value);
else if (this.type === tokTypes.name) {
const {value} = this;
node.source = this.parseLiteral(this.value);
node.source.raw = `'${value}'`;
} else {
this.unexpected();
}
}

const {raw, value} = node.source;
Expand Down
5 changes: 5 additions & 0 deletions packages/keyword-import/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ test('goldstein: keyword: import', (t) => {
t.compile('import');
t.end();
});

test('goldstein: keyword: import: identifier', (t) => {
t.compile('import-identifier');
t.end();
});

0 comments on commit 1554718

Please sign in to comment.