Skip to content

Commit

Permalink
fix: relative imports from parent directories (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-trunov authored Feb 9, 2024
1 parent db9ac5d commit 619a143
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Augmented assignment operators (`+=`, `-=`, `*=`, `/=` and `%=`): PR [#87](https://github.com/tact-lang/tact/pull/87)

### Fixed
- Relative imports from parent directories: PR [#125](https://github.com/tact-lang/tact/pull/125)

## [1.1.5] - 2023-12-01

### Added
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion src/imports/__testdata/project/main.tact
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import "./imported";
import "./imported"; import "./subfolder/import_from_parent";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "../imported_from_subfolder";
7 changes: 4 additions & 3 deletions src/imports/parseImportPath.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import path from "path";
import normalize from "path-normalize";

export function parseImportPath(src: string) {
if (!src.startsWith('./')) {
if (!(src.startsWith('./') || src.startsWith('../'))) {
return null;
}
if (src.endsWith('/')) {
return null;
}
return normalize(src.slice(2)).split('/');
}
return normalize(src).split('/');
}
10 changes: 9 additions & 1 deletion src/imports/resolveImports.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ describe('resolveImports', () => {
"path": path.resolve(__dirname, '__testdata', 'project', 'imported.tact'),
},
{
"code": "import \"./imported\";",
"code": "import \"../imported_from_subfolder\";",
"path": path.resolve(__dirname, '__testdata', 'project', 'subfolder', 'import_from_parent.tact'),
},
{
"code": "",
"path": path.resolve(__dirname, '__testdata', 'project', 'imported_from_subfolder.tact'),
},
{
"code": "import \"./imported\"; import \"./subfolder/import_from_parent\";",
"path": path.resolve(__dirname, '__testdata', 'project', 'main.tact'),
},
],
Expand Down

0 comments on commit 619a143

Please sign in to comment.