Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion napi/oxlint2/src-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Context {
physicalFilename: string;

/**
* @constructor
* @class
* @param fullRuleName - Rule name, in form `<plugin>/<rule>`
*/
constructor(fullRuleName: string) {
Expand Down
2 changes: 1 addition & 1 deletion napi/oxlint2/src-js/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type VisitFn = (node: Node) => void;

// AST node type.
// We'll make this type a union later on.
export type Node = Object;
export type Node = { type: string; start: number; end: number; [key: string]: unknown };

// Element of compiled visitor array.
// * `VisitFn | null` for leaf nodes.
Expand Down
1 change: 1 addition & 0 deletions napi/oxlint2/src-js/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export function getErrorMessage(err: unknown): string {
*
* @param value - Value
*/
// oxlint-disable-next-line no-unused-vars
export function assertIs<T>(value: unknown): asserts value is T {}
1 change: 1 addition & 0 deletions napi/oxlint2/src-js/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ function createMerger(fnCount: number): Merger {
}
body += '}';
args.push(body);
// oxlint-disable-next-line typescript-eslint/no-implied-eval
return new Function(...args) as Merger;
}

Expand Down
34 changes: 19 additions & 15 deletions napi/oxlint2/test/compile-visitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ describe('compile visitor', () => {
it('throws if visitor is not an object', () => {
const expectedErr = new TypeError('Visitor returned from `create` method must be an object');
expect(() => (addVisitorToCompiled as any)()).toThrow(expectedErr);
// oxlint-disable typescript-eslint/no-confusing-void-expression
expect(() => addVisitorToCompiled(null)).toThrow(expectedErr);
expect(() => addVisitorToCompiled(undefined)).toThrow(expectedErr);
expect(() => addVisitorToCompiled(true as any)).toThrow(expectedErr);
expect(() => addVisitorToCompiled('xyz' as any)).toThrow(expectedErr);
// oxlint-enable typescript-eslint/no-confusing-void-expression
});

it('throws if unknown visitor key', () => {
Expand All @@ -34,10 +36,12 @@ describe('compile visitor', () => {

it('throws if visitor property is not a function', () => {
const expectedErr = new TypeError("'Program' property of visitor object is not a function");
// oxlint-disable typescript-eslint/no-confusing-void-expression
expect(() => addVisitorToCompiled({ Program: null })).toThrow(expectedErr);
expect(() => addVisitorToCompiled({ Program: undefined })).toThrow(expectedErr);
expect(() => addVisitorToCompiled({ Program: true } as any)).toThrow(expectedErr);
expect(() => addVisitorToCompiled({ Program: {} } as any)).toThrow(expectedErr);
// oxlint-enable typescript-eslint/no-confusing-void-expression
});

describe('registers enter visitor', () => {
Expand Down Expand Up @@ -86,7 +90,7 @@ describe('compile visitor', () => {
addVisitorToCompiled({ EmptyStatement: enter, 'EmptyStatement:exit': exit });
expect(finalizeCompiledVisitor()).toBe(true);

const node = {};
const node = { type: 'EmptyStatement', start: 0, end: 0 };
(compiledVisitor[EMPTY_STMT_TYPE_ID] as VisitFn)(node);
expect(enter).toHaveBeenCalledWith(node);
expect(exit).toHaveBeenCalledWith(node);
Expand All @@ -99,7 +103,7 @@ describe('compile visitor', () => {
addVisitorToCompiled({ 'EmptyStatement:exit': exit, EmptyStatement: enter });
expect(finalizeCompiledVisitor()).toBe(true);

const node = {};
const node = { type: 'EmptyStatement', start: 0, end: 0 };
(compiledVisitor[EMPTY_STMT_TYPE_ID] as VisitFn)(node);
expect(enter).toHaveBeenCalledWith(node);
expect(exit).toHaveBeenCalledWith(node);
Expand Down Expand Up @@ -147,7 +151,7 @@ describe('compile visitor', () => {

expect(finalizeCompiledVisitor()).toBe(true);

const node = {};
const node = { type: 'EmptyStatement', start: 0, end: 0 };
(compiledVisitor[EMPTY_STMT_TYPE_ID] as VisitFn)(node);
expect(enter1).toHaveBeenCalledWith(node);
expect(exit1).toHaveBeenCalledWith(node);
Expand All @@ -169,7 +173,7 @@ describe('compile visitor', () => {

expect(finalizeCompiledVisitor()).toBe(true);

const node = {};
const node = { type: 'EmptyStatement', start: 0, end: 0 };
(compiledVisitor[EMPTY_STMT_TYPE_ID] as VisitFn)(node);
expect(enter1).toHaveBeenCalledWith(node);
expect(exit1).toHaveBeenCalledWith(node);
Expand All @@ -191,7 +195,7 @@ describe('compile visitor', () => {

expect(finalizeCompiledVisitor()).toBe(true);

const node = {};
const node = { type: 'EmptyStatement', start: 0, end: 0 };
(compiledVisitor[EMPTY_STMT_TYPE_ID] as VisitFn)(node);
expect(enter1).toHaveBeenCalledWith(node);
expect(exit1).toHaveBeenCalledWith(node);
Expand All @@ -213,7 +217,7 @@ describe('compile visitor', () => {

expect(finalizeCompiledVisitor()).toBe(true);

const node = {};
const node = { type: 'EmptyStatement', start: 0, end: 0 };
(compiledVisitor[EMPTY_STMT_TYPE_ID] as VisitFn)(node);
expect(enter1).toHaveBeenCalledWith(node);
expect(exit1).toHaveBeenCalledWith(node);
Expand All @@ -239,12 +243,12 @@ describe('compile visitor', () => {

const enterExit = compiledVisitor[PROGRAM_TYPE_ID] as EnterExit;

const enterNode = {};
const enterNode = { type: 'Program', start: 0, end: 0 };
enterExit.enter(enterNode);
expect(enter1).toHaveBeenCalledWith(enterNode);
expect(enter2).toHaveBeenCalledWith(enterNode);

const exitNode = {};
const exitNode = { type: 'Program', start: 0, end: 0 };
enterExit.exit(exitNode);
expect(exit1).toHaveBeenCalledWith(exitNode);
expect(exit2).toHaveBeenCalledWith(exitNode);
Expand All @@ -263,12 +267,12 @@ describe('compile visitor', () => {

const enterExit = compiledVisitor[PROGRAM_TYPE_ID] as EnterExit;

const enterNode = {};
const enterNode = { type: 'Program', start: 0, end: 0 };
enterExit.enter(enterNode);
expect(enter1).toHaveBeenCalledWith(enterNode);
expect(enter2).toHaveBeenCalledWith(enterNode);

const exitNode = {};
const exitNode = { type: 'Program', start: 0, end: 0 };
enterExit.exit(exitNode);
expect(exit1).toHaveBeenCalledWith(exitNode);
expect(exit2).toHaveBeenCalledWith(exitNode);
Expand All @@ -287,12 +291,12 @@ describe('compile visitor', () => {

const enterExit = compiledVisitor[PROGRAM_TYPE_ID] as EnterExit;

const enterNode = {};
const enterNode = { type: 'Program', start: 0, end: 0 };
enterExit.enter(enterNode);
expect(enter1).toHaveBeenCalledWith(enterNode);
expect(enter2).toHaveBeenCalledWith(enterNode);

const exitNode = {};
const exitNode = { type: 'Program', start: 0, end: 0 };
enterExit.exit(exitNode);
expect(exit1).toHaveBeenCalledWith(exitNode);
expect(exit2).toHaveBeenCalledWith(exitNode);
Expand All @@ -311,12 +315,12 @@ describe('compile visitor', () => {

const enterExit = compiledVisitor[PROGRAM_TYPE_ID] as EnterExit;

const enterNode = {};
const enterNode = { type: 'Program', start: 0, end: 0 };
enterExit.enter(enterNode);
expect(enter1).toHaveBeenCalledWith(enterNode);
expect(enter2).toHaveBeenCalledWith(enterNode);

const exitNode = {};
const exitNode = { type: 'Program', start: 0, end: 0 };
enterExit.exit(exitNode);
expect(exit1).toHaveBeenCalledWith(exitNode);
expect(exit2).toHaveBeenCalledWith(exitNode);
Expand Down Expand Up @@ -350,7 +354,7 @@ describe('compile visitor', () => {

expect(finalizeCompiledVisitor()).toBe(true);

const node = {};
const node = { type: 'EmptyStatement', start: 0, end: 0 };
(compiledVisitor[EMPTY_STMT_TYPE_ID] as VisitFn)(node);

expect(enter1).toHaveBeenCalledWith(node);
Expand Down
Loading