Skip to content

Commit 4250bd0

Browse files
committed
Changing import style to .js required extension for ESM
1 parent 3571171 commit 4250bd0

18 files changed

+55
-44
lines changed

src/ast/ast-types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* *AstNode* types where I was lazy or didn't know the core type.
55
*/
66

7-
import { Scope } from '../parser/scope';
7+
import { Scope } from '../parser/scope.js';
88

99
// The overall result of parsing, which incldues the AST and scopes
1010
export interface Program {

src/ast/ast.test.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import { AstNode, BinaryNode, IdentifierNode, LiteralNode } from './ast-types';
2-
import { visit } from './visit';
1+
import {
2+
AstNode,
3+
BinaryNode,
4+
IdentifierNode,
5+
LiteralNode,
6+
} from './ast-types.js';
7+
import { visit } from './visit.js';
38

49
const literal = <T>(literal: T): LiteralNode<T> => ({
510
type: 'literal',

src/ast/ast.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AstNode, Program } from './ast-types';
1+
import type { AstNode, Program } from './ast-types.js';
22

33
type NodeGenerator<NodeType> = (node: NodeType) => string;
44

src/ast/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from './ast';
2-
export * from './visit';
3-
export * from './ast-types';
1+
export * from './ast.js';
2+
export * from './visit.js';
3+
export * from './ast-types.js';

src/ast/visit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AstNode, Program } from './ast-types';
1+
import type { AstNode, Program } from './ast-types.js';
22

33
const isNode = (node: AstNode) => !!node?.type;
44
const isTraversable = (node: any) => isNode(node) || Array.isArray(node);

src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import generate from './parser/generator';
2-
import parser from './parser/parser';
1+
import generate from './parser/generator.js';
2+
import * as parser from './parser/parser.js';
33

4-
export type * from './error';
4+
export type * from './error.js';
55

66
export { generate, parser };

src/parser/generator.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { makeGenerator, makeEveryOtherGenerator, NodeGenerators } from '../ast';
1+
import {
2+
makeGenerator,
3+
makeEveryOtherGenerator,
4+
NodeGenerators,
5+
} from '../ast/index.js';
26

37
const generators: NodeGenerators = {
48
program: (node) => generate(node.wsStart) + generate(node.program),

src/parser/grammar.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import {
1616
TypeNameNode,
1717
FullySpecifiedTypeNode,
1818
TypeSpecifierNode,
19-
} from '../ast';
20-
import { ParserOptions } from './parser';
19+
} from '../ast/index.js';
20+
import { ParserOptions } from './parser.js';
2121
import {
2222
Scope,
2323
findGlobalScope,
@@ -30,7 +30,7 @@ import {
3030
isDeclaredType,
3131
makeScopeIndex,
3232
findBindingScope,
33-
} from './scope';
33+
} from './scope.js';
3434

3535
export {
3636
Scope,

src/parser/parse.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { FunctionCallNode, visit } from '../ast';
2-
import { GlslSyntaxError } from '../error';
3-
import { buildParser } from './test-helpers';
1+
import { FunctionCallNode, visit } from '../ast/index.js';
2+
import { GlslSyntaxError } from '../error.js';
3+
import { buildParser } from './test-helpers.js';
44

55
let c!: ReturnType<typeof buildParser>;
66
beforeAll(() => (c = buildParser()));

src/parser/scope.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import generate from './generator';
2-
import { renameBindings, renameFunctions, renameTypes } from './utils';
3-
import { UNKNOWN_TYPE } from './grammar';
4-
import { buildParser, nextWarn } from './test-helpers';
1+
import generate from './generator.js';
2+
import { renameBindings, renameFunctions, renameTypes } from './utils.js';
3+
import { UNKNOWN_TYPE } from './grammar.js';
4+
import { buildParser, nextWarn } from './test-helpers.js';
55

66
let c!: ReturnType<typeof buildParser>;
77
beforeAll(() => (c = buildParser()));

src/parser/scope.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
FunctionNode,
1010
FunctionCallNode,
1111
TypeNameNode,
12-
} from '../ast';
13-
import { xor } from './utils';
12+
} from '../ast/index.js';
13+
import { xor } from './utils.js';
1414

1515
export type TypeScopeEntry = {
1616
declaration?: TypeNameNode;

src/parser/test-helpers.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { execSync } from 'child_process';
22
import { GrammarError } from 'peggy';
33
import util from 'util';
4-
import generate from './generator';
5-
import { AstNode, FunctionNode, Program } from '../ast';
6-
import { Parse, ParserOptions } from './parser';
7-
import { FunctionScopeIndex, Scope, ScopeIndex } from './scope';
4+
import generate from './generator.js';
5+
import { AstNode, FunctionNode, Program } from '../ast/index.js';
6+
import { Parse, ParserOptions } from './parser.js';
7+
import { FunctionScopeIndex, Scope, ScopeIndex } from './scope.js';
88

99
export const inspect = (arg: any) =>
1010
console.log(util.inspect(arg, false, null, true));

src/parser/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { AstNode } from '../ast';
2-
import { Scope } from './scope';
1+
import type { AstNode } from '../ast/index.js';
2+
import { Scope } from './scope.js';
33

44
export const renameBindings = (
55
scope: Scope,

src/preprocessor/generator.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { makeGenerator, NodeGenerators } from '../ast';
2-
import { PreprocessorProgram } from './preprocessor';
3-
import { PreprocessorAstNode } from './preprocessor-node';
1+
import { makeGenerator, NodeGenerators } from '../ast/index.js';
2+
import { PreprocessorProgram } from './preprocessor.js';
3+
import { PreprocessorAstNode } from './preprocessor-node.js';
44

55
type NodeGenerator<NodeType> = (node: NodeType) => string;
66

src/preprocessor/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import generate from './generator';
1+
import generate from './generator.js';
22
import {
33
preprocessAst,
44
preprocessComments,
55
PreprocessorOptions,
6-
} from './preprocessor';
6+
} from './preprocessor.js';
77

88
// This index file is currently only for package publishing, where the whole
99
// library exists in the dist/ folder, so the below import is relative to dist/
10-
import parser from './preprocessor-parser.js';
10+
import * as parser from './preprocessor-parser.js';
1111

1212
// Should this be in a separate file? There's no tests for it either
1313
const preprocess = (src: string, options: PreprocessorOptions) =>

src/preprocessor/preprocessor.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55
preprocessComments,
66
preprocessAst,
77
PreprocessorProgram,
8-
} from './preprocessor';
9-
import generate from './generator';
10-
import { GlslSyntaxError } from '../error';
8+
} from './preprocessor.js';
9+
import generate from './generator.js';
10+
import { GlslSyntaxError } from '../error.js';
1111

1212
const fileContents = (filePath: string): string =>
1313
fs.readFileSync(filePath).toString();

src/preprocessor/preprocessor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { NodeVisitor, Path, visit } from '../ast/visit';
1+
import { NodeVisitor, Path, visit } from '../ast/visit.js';
22
import {
33
PreprocessorAstNode,
44
PreprocessorElseIfNode,
55
PreprocessorIdentifierNode,
66
PreprocessorIfNode,
77
PreprocessorLiteralNode,
88
PreprocessorSegmentNode,
9-
} from './preprocessor-node';
9+
} from './preprocessor-node.js';
1010

1111
export type PreprocessorProgram = {
1212
type: string;

tsconfig.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
"lib": ["ESNext"],
1010

1111
// Create ESM modules
12-
"module": "esnext",
12+
"module": "NodeNext",
1313
// Specify multiple folders that act like `./node_modules/@types`
1414
"typeRoots": [
1515
"node_modules/@types",
1616
"./preprocessor",
1717
"./parser"
18-
],
19-
18+
],
19+
20+
"moduleResolution": "NodeNext",
21+
2022
// Generate .d.ts files from TypeScript and JavaScript files in your project
2123
"declaration": true,
2224
// Specify an output folder for all emitted files.

0 commit comments

Comments
 (0)