Skip to content

Commit

Permalink
Changing import style to .js required extension for ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRayCode committed Apr 3, 2024
1 parent 3571171 commit 4250bd0
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/ast/ast-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions src/ast/ast.test.ts
Original file line number Diff line number Diff line change
@@ -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 = <T>(literal: T): LiteralNode<T> => ({
type: 'literal',
Expand Down
2 changes: 1 addition & 1 deletion src/ast/ast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AstNode, Program } from './ast-types';
import type { AstNode, Program } from './ast-types.js';

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

Expand Down
6 changes: 3 additions & 3 deletions src/ast/index.ts
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion src/ast/visit.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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 };
6 changes: 5 additions & 1 deletion src/parser/generator.ts
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
6 changes: 3 additions & 3 deletions src/parser/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -30,7 +30,7 @@ import {
isDeclaredType,
makeScopeIndex,
findBindingScope,
} from './scope';
} from './scope.js';

export {
Scope,
Expand Down
6 changes: 3 additions & 3 deletions src/parser/parse.test.ts
Original file line number Diff line number Diff line change
@@ -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<typeof buildParser>;
beforeAll(() => (c = buildParser()));
Expand Down
8 changes: 4 additions & 4 deletions src/parser/scope.test.ts
Original file line number Diff line number Diff line change
@@ -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<typeof buildParser>;
beforeAll(() => (c = buildParser()));
Expand Down
4 changes: 2 additions & 2 deletions src/parser/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/parser/test-helpers.ts
Original file line number Diff line number Diff line change
@@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/parser/utils.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/preprocessor/generator.ts
Original file line number Diff line number Diff line change
@@ -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<NodeType> = (node: NodeType) => string;

Expand Down
6 changes: 3 additions & 3 deletions src/preprocessor/index.ts
Original file line number Diff line number Diff line change
@@ -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) =>
Expand Down
6 changes: 3 additions & 3 deletions src/preprocessor/preprocessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/preprocessor/preprocessor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NodeVisitor, Path, visit } from '../ast/visit';
import { NodeVisitor, Path, visit } from '../ast/visit.js';
import {
PreprocessorAstNode,
PreprocessorElseIfNode,
PreprocessorIdentifierNode,
PreprocessorIfNode,
PreprocessorLiteralNode,
PreprocessorSegmentNode,
} from './preprocessor-node';
} from './preprocessor-node.js';

export type PreprocessorProgram = {
type: string;
Expand Down
8 changes: 5 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4250bd0

Please sign in to comment.