-
Notifications
You must be signed in to change notification settings - Fork 166
fix: ignore .ts and .js extensions form imports #437
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -260,7 +260,7 @@ attribute node_symbol = node => symbol = (source-text node), source_n | |||||
|
|
||||||
| ; expose globals | ||||||
| edge proj_scope -> @prog.globals | ||||||
|
|
||||||
| var mod_scope = proj_scope | ||||||
| if (not (is-empty @imexs)) { | ||||||
| ; module definition | ||||||
|
|
@@ -541,7 +541,9 @@ attribute node_symbol = node => symbol = (source-text node), source_n | |||||
| ; module reference | ||||||
| var mod_scope = mod_ref__ns | ||||||
| scan (path-normalize mod_path) { | ||||||
| "([^/]+)/?" { | ||||||
| ; ignore .js and .ts extensions on imports, as ts allows this | ||||||
| ; this might lead to false positives | ||||||
| "([^/|(\.j|ts)]+)/?" { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the idea is correct, bit this doesn't look quite right. What about this?
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually my regex is a bit of a hack but as .js (and .ts, ...) are included in this broad pattern:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding lazy matching with ? in the first group seems to fix the issue:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems the regex parser does not support non greedy matching ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see the problem! An alternative might be to keep the original regex, and strip any of the extensions off inside the body using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also tried a way using regexes and replace, but it seems the regex in tsg does not strictly behave as in rust: Outputs
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the implementation of functions.add(
"path-dir".into(),
path_fn(|p| p.parent().map(|s| s.as_os_str().to_os_string())),
);For instance I expect the dir of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got it to work by removing the explicit extensions (.js, .ts, .jsx, .tsx, not all extensions) with:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (tho this can be merged I believe)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My kingdom for a small coherent theory of paths 😭. Thanks for figuring out these cases. I'll put them in an issue so we document this in a more visible place. |
||||||
| node mod_ref | ||||||
| attr (mod_ref) push_symbol = $1 | ||||||
| edge mod_ref -> mod_scope | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /* --- path: src/foo.ts --- */ | ||
| export const bar = 42; | ||
|
|
||
| /* --- path: src/index.ts --- */ | ||
| import { bar } from "./foo.js"; | ||
| // ^ defined: 2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /* --- path: src/foo.ts --- */ | ||
| export const bar = 42; | ||
|
|
||
| /* --- path: src/index.ts --- */ | ||
| import { bar } from "./foo"; | ||
| // ^ defined: 2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /* --- path: src/foo.ts --- */ | ||
| export const bar = 42; | ||
|
|
||
| /* --- path: src/index.ts --- */ | ||
| import { bar } from "./foo.ts"; | ||
| // ^ defined: 2 |
Uh oh!
There was an error while loading. Please reload this page.