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
25 changes: 25 additions & 0 deletions apps/oxlint/src-js/generated/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,28 @@ export const SOURCE_START_OFFSET = 8;
* Byte offset of length of source text, relative to start of `Program`.
*/
export const SOURCE_LEN_OFFSET = 16;

/**
* Byte offset of comments `Vec` pointer, relative to start of `Program`.
*/
export const COMMENTS_OFFSET = 24;

/**
* Byte offset of comments `Vec` length, relative to start of `Program`.
*/
export const COMMENTS_LEN_OFFSET = 32;

/**
* Size of `Comment` struct in bytes.
*/
export const COMMENT_SIZE = 16;

/**
* Byte offset of `kind` field, relative to start of `Comment` struct.
*/
export const COMMENT_KIND_OFFSET = 12;

/**
* Discriminant value for `CommentKind::Line`.
*/
export const COMMENT_LINE_KIND = 0;
4 changes: 2 additions & 2 deletions apps/oxlint/src-js/generated/deserialize.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/raw_transfer.rs`.

import type { Program } from "./types.d.ts";
import type { Node, Comment } from "../plugins/types.ts";
import type { Node } from "../plugins/types.ts";
import type { Location as SourceLocation } from "../plugins/location.ts";

type BufferWithArrays = Uint8Array & { uint32: Uint32Array; float64: Float64Array };
type GetLoc = (node: Node | Comment) => SourceLocation;
type GetLoc = (node: Node) => SourceLocation;

export declare function deserializeProgramOnly(
buffer: BufferWithArrays,
Expand Down
65 changes: 3 additions & 62 deletions apps/oxlint/src-js/generated/deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/raw_transfer.rs`.

import { tokens, initTokens } from "../plugins/tokens.js";
import { comments, initComments } from "../plugins/comments.js";

let uint8,
uint32,
float64,
sourceText,
sourceIsAscii,
sourceStartPos,
astId = 0,
parent = null,
getLoc;

Expand Down Expand Up @@ -49,38 +49,18 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLen, getLocInput, de
export function resetBuffer() {
// Clear buffer and source text string to allow them to be garbage collected
uint8 = uint32 = float64 = sourceText = void 0;
astId++;
}

function deserializeProgram(pos) {
let localAstId = astId,
end = deserializeU32(pos + 4),
let end = deserializeU32(pos + 4),
program = (parent = {
__proto__: NodeProto,
type: "Program",
body: null,
sourceType: deserializeModuleKind(pos + 137),
hashbang: null,
get comments() {
// Check AST in buffer is still the same AST (buffers are reused)
if (localAstId !== astId)
throw Error("Comments are only accessible while linting the file");
// Deserialize the comments.
// Replace this getter with the comments array, so we don't deserialize twice.
let comments = deserializeVecComment(pos + 24),
{ hashbang } = this;
if (hashbang !== null) {
let start, end;
comments.unshift({
__proto__: NodeProto,
type: "Shebang",
value: hashbang.value,
start: (start = hashbang.start),
end: (end = hashbang.end),
range: [start, end],
});
}
Object.defineProperty(this, "comments", { value: comments });
comments === null && initComments();
return comments;
},
get tokens() {
Expand Down Expand Up @@ -5744,33 +5724,6 @@ function deserializeJSDocUnknownType(pos) {
};
}

function deserializeCommentKind(pos) {
switch (uint8[pos]) {
case 0:
return "Line";
case 1:
return "Block";
case 2:
return "Block";
default:
throw Error(`Unexpected discriminant ${uint8[pos]} for CommentKind`);
}
}

function deserializeComment(pos) {
let type = deserializeCommentKind(pos + 12),
start = deserializeU32(pos),
end = deserializeU32(pos + 4);
return {
__proto__: NodeProto,
type,
value: sourceText.slice(start + 2, end - (type === "Line" ? 0 : 2)),
start,
end,
range: [start, end],
};
}

function deserializeAssignmentOperator(pos) {
switch (uint8[pos]) {
case 0:
Expand Down Expand Up @@ -5951,18 +5904,6 @@ function deserializeStr(pos) {
return out;
}

function deserializeVecComment(pos) {
let arr = [],
pos32 = pos >> 2;
pos = uint32[pos32];
let endPos = pos + uint32[pos32 + 2] * 16;
for (; pos !== endPos; ) {
arr.push(deserializeComment(pos));
pos += 16;
}
return arr;
}

function deserializeOptionHashbang(pos) {
if (uint32[(pos + 8) >> 2] === 0 && uint32[(pos + 12) >> 2] === 0) return null;
return deserializeHashbang(pos);
Expand Down
9 changes: 5 additions & 4 deletions apps/oxlint/src-js/generated/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/typescript.rs`.

import { Span } from "../plugins/location.ts";
import { Token } from "../plugins/tokens.ts";
import { Comment } from "../plugins/types.ts";
export { Span, Comment, Token };
import type { Comment } from "../plugins/comments.ts";
import type { Span } from "../plugins/location.ts";
import type { Token } from "../plugins/tokens.ts";

export type { Comment, Span, Token };

export interface Program extends Span {
type: "Program";
Expand Down
10 changes: 2 additions & 8 deletions apps/oxlint/src-js/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export { eslintCompatPlugin } from "./package/compat.ts";
export type * as ESTree from "./generated/types";

// Plugin types
export type { Comment } from "./plugins/comments.ts";
export type { Context, LanguageOptions } from "./plugins/context.ts";
export type { Fix, Fixer, FixFn } from "./plugins/fix.ts";
export type { Globals, Envs } from "./plugins/globals.ts";
Expand Down Expand Up @@ -52,11 +53,4 @@ export type {
RuleReplacedByExternalSpecifier,
} from "./plugins/rule_meta.ts";
export type { LineColumn, Location, Range, Ranged, Span } from "./plugins/location.ts";
export type {
AfterHook,
BeforeHook,
Comment,
Node,
Visitor,
VisitorWithHooks,
} from "./plugins/types.ts";
export type { AfterHook, BeforeHook, Node, Visitor, VisitorWithHooks } from "./plugins/types.ts";
Loading
Loading