Skip to content

Commit

Permalink
fix(api): return AST import nodes from parseImports instead of stri…
Browse files Browse the repository at this point in the history
…ngs (#966)
  • Loading branch information
Esorat authored Oct 17, 2024
1 parent bd1d115 commit 1510fbe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- The `parseImports` function now returns AST import nodes instead of raw strings: PR [#966](https://github.com/tact-lang/tact/pull/966)
- Optional types for `self` argument in `extends mutates` functions are now allowed: PR [#854](https://github.com/tact-lang/tact/pull/854)

### Fixed
Expand Down
6 changes: 2 additions & 4 deletions src/grammar/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1509,17 +1509,15 @@ export function parseImports(
src: string,
path: string,
origin: ItemOrigin,
): string[] {
): AstImport[] {
return inFile(path, () => {
const matchResult = tactGrammar.match(src, "JustImports");
if (matchResult.failed()) {
throwParseError(matchResult, path, origin);
}
ctx = { origin };
try {
const imports: AstImport[] =
semantics(matchResult).astOfJustImports();
return imports.map((imp) => imp.path.value);
return semantics(matchResult).astOfJustImports();
} finally {
ctx = null;
}
Expand Down
5 changes: 3 additions & 2 deletions src/imports/resolveImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ export function resolveImports(args: {
function processImports(source: string, path: string, origin: ItemOrigin) {
const imp = parseImports(source, path, origin);
for (const i of imp) {
const importPath = i.path.value;
// Resolve library
const resolved = resolveLibrary({
path: path,
name: i,
name: importPath,
project: args.project,
stdlib: args.stdlib,
});
if (!resolved.ok) {
throwCompilationError(
`Could not resolve import "${i}" in ${path}`,
`Could not resolve import "${importPath}" in ${path}`,
);
}

Expand Down

0 comments on commit 1510fbe

Please sign in to comment.