Skip to content

Commit

Permalink
Infer version (#1047)
Browse files Browse the repository at this point in the history
* update dependencies

* Adding the compiler inference logic

* upgrading tests for version inferrence

* Since importing maxSatisfying and minSatisfying, there is no benefit in importing semver functionality by independent functions.

* fixing bug in VersionLiteral

* using string replace to remove all comments from the VersionExpressionSets

* Move inferLanguage to its own module

* Add tests for inferLanguage

* added extra test case

* check if there is at least 1 valid version in the ranges before comparing it against the supported versions.

* adding more specific tests

* validating a range like `0.5.0 - 0.6.0` gets rewritten to comparators `>=0.5.0 <=0.6.0` which can be concatenated.

* refactor test

* Add test case for infer-language

---------

Co-authored-by: Franco Victorio <[email protected]>
  • Loading branch information
Janther and fvictorio authored Oct 1, 2024
1 parent 3551102 commit 44a48ea
Show file tree
Hide file tree
Showing 55 changed files with 441 additions and 263 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if (TEST_STANDALONE) {
);
} else {
testMatch.push('<rootDir>/tests/unit/**/*.test.js');
testMatch.push('<rootDir>/tests/unit/**/*.test.ts');
}

export default {
Expand Down
159 changes: 92 additions & 67 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@
},
"devDependencies": {
"@babel/code-frame": "^7.24.7",
"@types/jest": "^29.5.13",
"@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "^8.6.0",
"@typescript-eslint/parser": "^8.6.0",
"@typescript-eslint/eslint-plugin": "^8.7.0",
"@typescript-eslint/parser": "^8.7.0",
"c8": "^9.1.0",
"cross-env": "^7.0.3",
"eslint": "^9.10.0",
"eslint": "^9.11.1",
"eslint-config-prettier": "^9.1.0",
"esm-utils": "^4.3.0",
"esmock": "^2.6.7",
Expand All @@ -96,7 +97,7 @@
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "^5.5.4",
"webpack": "^5.94.0",
"webpack": "^5.95.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
Expand Down
3 changes: 1 addition & 2 deletions src/slang-nodes/ContractDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { doc } from 'prettier';
import coerce from 'semver/functions/coerce.js';
import satisfies from 'semver/functions/satisfies.js';
import { coerce, satisfies } from 'semver';
import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js';
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
import { Identifier } from './Identifier.js';
Expand Down
3 changes: 1 addition & 2 deletions src/slang-nodes/FunctionDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import coerce from 'semver/functions/coerce.js';
import satisfies from 'semver/functions/satisfies.js';
import { coerce, satisfies } from 'semver';
import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js';
import { printFunction } from '../slang-printers/print-function.js';
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
Expand Down
3 changes: 1 addition & 2 deletions src/slang-nodes/ImportDeconstructionSymbols.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { doc } from 'prettier';
import coerce from 'semver/functions/coerce.js';
import satisfies from 'semver/functions/satisfies.js';
import { coerce, satisfies } from 'semver';
import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js';
import { printSeparatedList } from '../slang-printers/print-separated-list.js';
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
Expand Down
4 changes: 3 additions & 1 deletion src/slang-nodes/VersionLiteral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export class VersionLiteral implements SlangNode {
}

print(path: AstPath<VersionLiteral>, print: PrintFunction): Doc {
return path.call(print, 'variant');
return typeof this.variant === 'string'
? this.variant
: path.call(print, 'variant');
}
}
Loading

0 comments on commit 44a48ea

Please sign in to comment.