diff --git a/src/ast/ast-types.ts b/src/ast/ast-types.ts index 850dec1..8449d6f 100644 --- a/src/ast/ast-types.ts +++ b/src/ast/ast-types.ts @@ -4,7 +4,7 @@ * *AstNode* types where I was lazy or didn't know the core type. */ -import { Scope } from '../parser/scope'; +import { Scope } from '../parser/scope.js'; // The overall result of parsing, which incldues the AST and scopes export interface Program { diff --git a/src/ast/ast.test.ts b/src/ast/ast.test.ts index 593f694..c99e82e 100644 --- a/src/ast/ast.test.ts +++ b/src/ast/ast.test.ts @@ -1,5 +1,10 @@ -import { AstNode, BinaryNode, IdentifierNode, LiteralNode } from './ast-types'; -import { visit } from './visit'; +import { + AstNode, + BinaryNode, + IdentifierNode, + LiteralNode, +} from './ast-types.js'; +import { visit } from './visit.js'; const literal = (literal: T): LiteralNode => ({ type: 'literal', diff --git a/src/ast/ast.ts b/src/ast/ast.ts index 868962b..18a6919 100644 --- a/src/ast/ast.ts +++ b/src/ast/ast.ts @@ -1,4 +1,4 @@ -import type { AstNode, Program } from './ast-types'; +import type { AstNode, Program } from './ast-types.js'; type NodeGenerator = (node: NodeType) => string; diff --git a/src/ast/index.ts b/src/ast/index.ts index 94b3dd9..8810bf8 100644 --- a/src/ast/index.ts +++ b/src/ast/index.ts @@ -1,3 +1,3 @@ -export * from './ast'; -export * from './visit'; -export * from './ast-types'; +export * from './ast.js'; +export * from './visit.js'; +export * from './ast-types.js'; diff --git a/src/ast/visit.ts b/src/ast/visit.ts index 5f91d10..522102c 100644 --- a/src/ast/visit.ts +++ b/src/ast/visit.ts @@ -1,4 +1,4 @@ -import type { AstNode, Program } from './ast-types'; +import type { AstNode, Program } from './ast-types.js'; const isNode = (node: AstNode) => !!node?.type; const isTraversable = (node: any) => isNode(node) || Array.isArray(node); diff --git a/src/index.ts b/src/index.ts index f8d1902..9e35188 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ -import generate from './parser/generator'; -import parser from './parser/parser'; +import generate from './parser/generator.js'; +import * as parser from './parser/parser.js'; -export type * from './error'; +export type * from './error.js'; export { generate, parser }; diff --git a/src/parser/generator.ts b/src/parser/generator.ts index 8b0622c..14bfd72 100644 --- a/src/parser/generator.ts +++ b/src/parser/generator.ts @@ -1,4 +1,8 @@ -import { makeGenerator, makeEveryOtherGenerator, NodeGenerators } from '../ast'; +import { + makeGenerator, + makeEveryOtherGenerator, + NodeGenerators, +} from '../ast/index.js'; const generators: NodeGenerators = { program: (node) => generate(node.wsStart) + generate(node.program), diff --git a/src/parser/grammar.ts b/src/parser/grammar.ts index 64c3a5f..eb289c4 100644 --- a/src/parser/grammar.ts +++ b/src/parser/grammar.ts @@ -16,8 +16,8 @@ import { TypeNameNode, FullySpecifiedTypeNode, TypeSpecifierNode, -} from '../ast'; -import { ParserOptions } from './parser'; +} from '../ast/index.js'; +import { ParserOptions } from './parser.js'; import { Scope, findGlobalScope, @@ -30,7 +30,7 @@ import { isDeclaredType, makeScopeIndex, findBindingScope, -} from './scope'; +} from './scope.js'; export { Scope, diff --git a/src/parser/parse.test.ts b/src/parser/parse.test.ts index 5108551..e088a31 100644 --- a/src/parser/parse.test.ts +++ b/src/parser/parse.test.ts @@ -1,6 +1,6 @@ -import { FunctionCallNode, visit } from '../ast'; -import { GlslSyntaxError } from '../error'; -import { buildParser } from './test-helpers'; +import { FunctionCallNode, visit } from '../ast/index.js'; +import { GlslSyntaxError } from '../error.js'; +import { buildParser } from './test-helpers.js'; let c!: ReturnType; beforeAll(() => (c = buildParser())); diff --git a/src/parser/scope.test.ts b/src/parser/scope.test.ts index 81cf626..d3e9733 100644 --- a/src/parser/scope.test.ts +++ b/src/parser/scope.test.ts @@ -1,7 +1,7 @@ -import generate from './generator'; -import { renameBindings, renameFunctions, renameTypes } from './utils'; -import { UNKNOWN_TYPE } from './grammar'; -import { buildParser, nextWarn } from './test-helpers'; +import generate from './generator.js'; +import { renameBindings, renameFunctions, renameTypes } from './utils.js'; +import { UNKNOWN_TYPE } from './grammar.js'; +import { buildParser, nextWarn } from './test-helpers.js'; let c!: ReturnType; beforeAll(() => (c = buildParser())); diff --git a/src/parser/scope.ts b/src/parser/scope.ts index 9955f83..15b0bd5 100644 --- a/src/parser/scope.ts +++ b/src/parser/scope.ts @@ -9,8 +9,8 @@ import { FunctionNode, FunctionCallNode, TypeNameNode, -} from '../ast'; -import { xor } from './utils'; +} from '../ast/index.js'; +import { xor } from './utils.js'; export type TypeScopeEntry = { declaration?: TypeNameNode; diff --git a/src/parser/test-helpers.ts b/src/parser/test-helpers.ts index deb937f..90cb8d3 100644 --- a/src/parser/test-helpers.ts +++ b/src/parser/test-helpers.ts @@ -1,10 +1,10 @@ import { execSync } from 'child_process'; import { GrammarError } from 'peggy'; import util from 'util'; -import generate from './generator'; -import { AstNode, FunctionNode, Program } from '../ast'; -import { Parse, ParserOptions } from './parser'; -import { FunctionScopeIndex, Scope, ScopeIndex } from './scope'; +import generate from './generator.js'; +import { AstNode, FunctionNode, Program } from '../ast/index.js'; +import { Parse, ParserOptions } from './parser.js'; +import { FunctionScopeIndex, Scope, ScopeIndex } from './scope.js'; export const inspect = (arg: any) => console.log(util.inspect(arg, false, null, true)); diff --git a/src/parser/utils.ts b/src/parser/utils.ts index 8ae9eed..78438b7 100644 --- a/src/parser/utils.ts +++ b/src/parser/utils.ts @@ -1,5 +1,5 @@ -import type { AstNode } from '../ast'; -import { Scope } from './scope'; +import type { AstNode } from '../ast/index.js'; +import { Scope } from './scope.js'; export const renameBindings = ( scope: Scope, diff --git a/src/preprocessor/generator.ts b/src/preprocessor/generator.ts index c615754..d557f07 100644 --- a/src/preprocessor/generator.ts +++ b/src/preprocessor/generator.ts @@ -1,6 +1,6 @@ -import { makeGenerator, NodeGenerators } from '../ast'; -import { PreprocessorProgram } from './preprocessor'; -import { PreprocessorAstNode } from './preprocessor-node'; +import { makeGenerator, NodeGenerators } from '../ast/index.js'; +import { PreprocessorProgram } from './preprocessor.js'; +import { PreprocessorAstNode } from './preprocessor-node.js'; type NodeGenerator = (node: NodeType) => string; diff --git a/src/preprocessor/index.ts b/src/preprocessor/index.ts index d41a508..4c1a89c 100644 --- a/src/preprocessor/index.ts +++ b/src/preprocessor/index.ts @@ -1,13 +1,13 @@ -import generate from './generator'; +import generate from './generator.js'; import { preprocessAst, preprocessComments, PreprocessorOptions, -} from './preprocessor'; +} from './preprocessor.js'; // This index file is currently only for package publishing, where the whole // library exists in the dist/ folder, so the below import is relative to dist/ -import parser from './preprocessor-parser.js'; +import * as parser from './preprocessor-parser.js'; // Should this be in a separate file? There's no tests for it either const preprocess = (src: string, options: PreprocessorOptions) => diff --git a/src/preprocessor/preprocessor.test.ts b/src/preprocessor/preprocessor.test.ts index 322afb0..d5ef685 100644 --- a/src/preprocessor/preprocessor.test.ts +++ b/src/preprocessor/preprocessor.test.ts @@ -5,9 +5,9 @@ import { preprocessComments, preprocessAst, PreprocessorProgram, -} from './preprocessor'; -import generate from './generator'; -import { GlslSyntaxError } from '../error'; +} from './preprocessor.js'; +import generate from './generator.js'; +import { GlslSyntaxError } from '../error.js'; const fileContents = (filePath: string): string => fs.readFileSync(filePath).toString(); diff --git a/src/preprocessor/preprocessor.ts b/src/preprocessor/preprocessor.ts index e666653..a07ed47 100644 --- a/src/preprocessor/preprocessor.ts +++ b/src/preprocessor/preprocessor.ts @@ -1,4 +1,4 @@ -import { NodeVisitor, Path, visit } from '../ast/visit'; +import { NodeVisitor, Path, visit } from '../ast/visit.js'; import { PreprocessorAstNode, PreprocessorElseIfNode, @@ -6,7 +6,7 @@ import { PreprocessorIfNode, PreprocessorLiteralNode, PreprocessorSegmentNode, -} from './preprocessor-node'; +} from './preprocessor-node.js'; export type PreprocessorProgram = { type: string; diff --git a/tsconfig.json b/tsconfig.json index b0250ed..1bb622b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,14 +9,16 @@ "lib": ["ESNext"], // Create ESM modules - "module": "esnext", + "module": "NodeNext", // Specify multiple folders that act like `./node_modules/@types` "typeRoots": [ "node_modules/@types", "./preprocessor", "./parser" - ], - + ], + + "moduleResolution": "NodeNext", + // Generate .d.ts files from TypeScript and JavaScript files in your project "declaration": true, // Specify an output folder for all emitted files.