Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add projects to test typescript support with different compiler options #4597

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions runtime/JavaScript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,24 @@
},
"scripts": {
"build": "webpack",
"test": "jasmine",
"test": "jasmine && npm run test:builds",
"test:builds": "bash test-builds.sh",
"coverage": "c8 jasmine",
"lint": "eslint src/antlr4/"
"lint": "eslint src/antlr4/",
"prepack": "npm run build"
},
"engines": {
"node": ">=16"
},
"exports": {
".": {
"types": "./src/antlr4/index.d.ts",
"node": {
"types": "./src/antlr4/index.d.ts",
"import": "./dist/antlr4.node.mjs",
"require": "./dist/antlr4.node.cjs",
"default": "./dist/antlr4.node.mjs"
},
"browser": {
"types": "./src/antlr4/index.d.ts",
"import": "./dist/antlr4.web.mjs",
"require": "./dist/antlr4.web.cjs",
"default": "./dist/antlr4.web.mjs"
Expand Down
3 changes: 3 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-cjs-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules

package-lock.json
5 changes: 5 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-cjs-ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { CharStream } = require("antlr4");

const cs = new CharStream("OK");

console.log(cs.toString());
18 changes: 18 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-cjs-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "test-import-node-cjs-ts",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "commonjs",
"scripts": {
"test": "bash test.sh"
},
"author": "",
"license": "ISC",
"dependencies": {
"antlr4": "file:../../../.."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we be using a local build rather than the source folder ?

},
"devDependencies": {
"typescript": "^5.4.3"
}
}
19 changes: 19 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-cjs-ts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

tsconfigFiles=(
"tsconfig.node.commonjs.json"
)

failure=0

for tsconfig in "${tsconfigFiles[@]}"; do
echo -n "$tsconfig "

./node_modules/.bin/tsc -p $tsconfig || { failure=1 ; echo "FAIL tsc: $tsconfig"; }
result=$(node ./tsOutput/index.js)
[[ $result == "OK" ]] && echo "OK"
[[ $result != "OK" ]] && { failure=1 ; echo "FAIL loading runtime with config: $tsconfig"; }
rm -rf ./tsOutput
done

exit $failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"skipLibCheck": true,
"outDir": "./tsOutput",
"module": "commonjs",
"moduleResolution": "node"
},
"include": ["index.ts"],
}
3 changes: 3 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-esm-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules

package-lock.json
5 changes: 5 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-esm-ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { CharStream } from "antlr4";

const cs = new CharStream("OK");

console.log(cs.toString());
18 changes: 18 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-esm-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "test-import-node-esm-ts",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "bash test.sh"
},
"author": "",
"license": "ISC",
"dependencies": {
"antlr4": "file:../../../.."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we be using a local build rather than the source folder ?

},
"devDependencies": {
"typescript": "^5.4.3"
}
}
20 changes: 20 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-esm-ts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

tsconfigFiles=(
"tsconfig.node16.json"
"tsconfig.bundler.es2022.json"
)

failure=0

for tsconfig in "${tsconfigFiles[@]}"; do
echo -n "$tsconfig "

./node_modules/.bin/tsc -p $tsconfig || { failure=1 ; echo "FAIL tsc: $tsconfig"; }
result=$(node ./tsOutput/index.js)
[[ $result == "OK" ]] && echo "OK"
[[ $result != "OK" ]] && { failure=1 ; echo "FAIL loading runtime with config: $tsconfig"; }
rm -rf ./tsOutput
done

exit $failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"skipLibCheck": true,
"outDir": "./tsOutput",
"module": "es2022",
"moduleResolution": "bundler"
},
"include": ["index.ts"],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"skipLibCheck": true,
"outDir": "./tsOutput",
"module": "node16",
"moduleResolution": "node16"
},
"include": ["index.ts"],
}
3 changes: 3 additions & 0 deletions runtime/JavaScript/spec/imports/builds/pnpm-esm-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules

package-lock.json
9 changes: 9 additions & 0 deletions runtime/JavaScript/spec/imports/builds/pnpm-esm-ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { CharStream, ErrorListener } from "antlr4";

const cs = new CharStream("OK");

class MyErrorListener<T> extends ErrorListener<T> {

}

console.log(cs.toString());
20 changes: 20 additions & 0 deletions runtime/JavaScript/spec/imports/builds/pnpm-esm-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "test-import-pnpm-esm-ts",
"version": "1.0.0",
"packageManager": "pnpm@9.0.6",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"preinstall": "npx only-allow pnpm",
"test": "bash test.sh"
},
"author": "",
"license": "ISC",
"dependencies": {
"antlr4": "file:../../../.."
},
"devDependencies": {
"typescript": "^5.4.5"
}
}
34 changes: 34 additions & 0 deletions runtime/JavaScript/spec/imports/builds/pnpm-esm-ts/pnpm-lock.yaml

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

20 changes: 20 additions & 0 deletions runtime/JavaScript/spec/imports/builds/pnpm-esm-ts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

tsconfigFiles=(
"tsconfig.node16.json"
"tsconfig.bundler.es2022.json"
)

failure=0

for tsconfig in "${tsconfigFiles[@]}"; do
echo -n "$tsconfig "

./node_modules/.bin/tsc -p $tsconfig || { failure=1 ; echo "FAIL tsc: $tsconfig"; }
result=$(node ./tsOutput/index.js)
[[ $result == "OK" ]] && echo "OK"
[[ $result != "OK" ]] && { failure=1 ; echo "FAIL loading runtime with config: $tsconfig"; }
rm -rf ./tsOutput
done

exit $failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"skipLibCheck": true,
"outDir": "./tsOutput",
"module": "es2022",
"moduleResolution": "bundler"
},
"include": ["index.ts"],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"skipLibCheck": true,
"outDir": "./tsOutput",
"module": "node16",
"moduleResolution": "node16"
},
"include": ["index.ts"],
}
4 changes: 2 additions & 2 deletions runtime/JavaScript/src/antlr4/BufferedTokenStream.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TokenStream } from './TokenStream';
import { Lexer } from "./Lexer";
import { TokenStream } from './TokenStream.js';
import { Lexer } from "./Lexer.js";

export declare class BufferedTokenStream extends TokenStream {

Expand Down
2 changes: 1 addition & 1 deletion runtime/JavaScript/src/antlr4/CharStreams.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CharStream} from "./CharStream";
import {CharStream} from './CharStream.js';

export declare class CharStreams {
static fromString(data: string, decodeToUnicodeCodePoints?: boolean): CharStream;
Expand Down
6 changes: 3 additions & 3 deletions runtime/JavaScript/src/antlr4/CommonToken.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Token } from "./Token";
import {InputStream} from "./InputStream";
import {TokenSource} from "./TokenSource";
import { Token } from './Token.js';
import {InputStream} from './InputStream.js';
import {TokenSource} from './TokenSource.js';

export declare class CommonToken extends Token {
constructor(source: [ TokenSource, InputStream ], type: number, channel: number, start: number, stop: number);
Expand Down
6 changes: 3 additions & 3 deletions runtime/JavaScript/src/antlr4/CommonTokenStream.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Lexer} from "./Lexer";
import {BufferedTokenStream} from "./BufferedTokenStream";
import {Token} from "./Token";
import {Lexer} from './Lexer.js';
import {BufferedTokenStream} from './BufferedTokenStream.js';
import {Token} from './Token.js';

export declare class CommonTokenStream extends BufferedTokenStream {
// properties
Expand Down
2 changes: 1 addition & 1 deletion runtime/JavaScript/src/antlr4/FileStream.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CharStream} from "./CharStream";
import {CharStream} from './CharStream.js';

export declare class FileStream extends CharStream {

Expand Down
8 changes: 4 additions & 4 deletions runtime/JavaScript/src/antlr4/Lexer.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Recognizer} from "./Recognizer";
import {LexerATNSimulator} from "./atn";
import {CharStream} from "./CharStream";
import {Token} from "./Token";
import {Recognizer} from './Recognizer.js';
import {LexerATNSimulator} from './atn/index.js';
import {CharStream} from './CharStream.js';
import {Token} from './Token.js';

export declare class Lexer extends Recognizer<number> {

Expand Down
18 changes: 9 additions & 9 deletions runtime/JavaScript/src/antlr4/Parser.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {TokenStream} from "./TokenStream";
import {Recognizer} from "./Recognizer";
import {ErrorStrategy, RecognitionException} from "./error";
import {IntervalSet} from "./misc";
import {ParserATNSimulator} from "./atn";
import {Token} from "./Token";
import {ParserRuleContext} from "./context";
import {Printer} from "./utils";
import {ParseTreeListener} from "./tree";
import {TokenStream} from "./TokenStream.js";
import {Recognizer} from "./Recognizer.js";
import {ErrorStrategy, RecognitionException} from "./error/index.js";
import {IntervalSet} from "./misc/index.js";
import {ParserATNSimulator} from "./atn/index.js";
import {Token} from "./Token.js";
import {ParserRuleContext} from "./context/index.js";
import {Printer} from "./utils/index.js";
import {ParseTreeListener} from "./tree/index.js";

export declare class Parser extends Recognizer<Token> {

Expand Down
2 changes: 1 addition & 1 deletion runtime/JavaScript/src/antlr4/Recognizer.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ErrorListener} from "./error";
import {ErrorListener} from './error/index.js';

export declare class Recognizer<TSymbol> {

Expand Down
4 changes: 2 additions & 2 deletions runtime/JavaScript/src/antlr4/Token.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TokenSource } from "./TokenSource";
import { CharStream } from "./CharStream";
import { TokenSource } from './TokenSource.js';
import { CharStream } from './CharStream.js';

export declare class Token {

Expand Down
4 changes: 2 additions & 2 deletions runtime/JavaScript/src/antlr4/TokenStream.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Interval} from "./misc";
import {Token} from "./Token";
import {Interval} from './misc/index.js';
import {Token} from './Token.js';

export declare class TokenStream {

Expand Down
6 changes: 3 additions & 3 deletions runtime/JavaScript/src/antlr4/TokenStreamRewriter.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommonTokenStream } from "./CommonTokenStream";
import { Token } from "./Token";
import { Interval } from "./misc/Interval";
import { CommonTokenStream } from './CommonTokenStream.js';
import { Token } from './Token.js';
import { Interval } from './misc/Interval.js';

type Rewrites = Array<RewriteOperation | undefined>;
type Text = unknown;
Expand Down
6 changes: 3 additions & 3 deletions runtime/JavaScript/src/antlr4/atn/ATN.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IntervalSet} from "../misc";
import {RuleContext} from "../context";
import {ATNState, DecisionState, RuleStartState, RuleStopState} from "../state";
import {IntervalSet} from "../misc/index.js";
import {RuleContext} from "../context/index.js";
import {ATNState, DecisionState, RuleStartState, RuleStopState} from "../state/index.js";

export declare class ATN {

Expand Down