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
4 changes: 2 additions & 2 deletions apps/oxlint/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ console.log('- Created package.json');
console.log('Copying files from parser...');

const parserFilePaths = [
'raw-transfer/lazy-common.mjs',
'raw-transfer/node-array.mjs',
'src-js/raw-transfer/lazy-common.mjs',
'src-js/raw-transfer/node-array.mjs',
'generated/lazy/constructors.mjs',
'generated/lazy/types.mjs',
'generated/lazy/walk.mjs',
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/src-js/plugins/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { assertIs } from './utils.js';
import { addVisitorToCompiled, compiledVisitor, finalizeCompiledVisitor, initCompiledVisitor } from './visitor.js';

// @ts-expect-error we need to generate `.d.ts` file for this module.
import { TOKEN } from '../../dist/raw-transfer/lazy-common.mjs';
import { TOKEN } from '../../dist/src-js/raw-transfer/lazy-common.mjs';
// @ts-expect-error we need to generate `.d.ts` file for this module.
import { walkProgram } from '../../dist/generated/lazy/walk.mjs';

Expand Down
14 changes: 7 additions & 7 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
"apps/oxlint/src-js/bindings.js",
"apps/oxlint/src-js/bindings.d.ts",
"napi/{transform,minify,playground}/index.js",
"napi/{parser,transform,minify,playground}/index.d.ts",
"napi/{parser,transform,minify,playground}/*.wasi-browser.js",
"napi/{parser,transform,minify,playground}/*.wasi.cjs",
"napi/{parser,transform,minify,playground}/wasi-worker-browser.mjs",
"napi/{parser,transform,minify,playground}/wasi-worker.mjs",
"napi/{parser,transform,minify,playground}/browser.js",
"napi/parser/bindings.mjs",
"napi/{parser,transform,minify,playground}/**/index.d.ts",
"napi/{parser,transform,minify,playground}/**/*.wasi-browser.js",
"napi/{parser,transform,minify,playground}/**/*.wasi.cjs",
"napi/{parser,transform,minify,playground}/**/wasi-worker-browser.mjs",
"napi/{parser,transform,minify,playground}/**/wasi-worker.mjs",
"napi/{parser,transform,minify,playground}/**/browser.js",
"napi/parser/src-js/bindings.mjs",
"npm/*/package.json",
"npm/oxlint/configuration_schema.json",
"npm/oxc-wasm/**",
Expand Down
10 changes: 5 additions & 5 deletions napi/parser/bench.bench.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { writeFile } from 'node:fs/promises';
import { join as pathJoin } from 'node:path';
import { bench, describe } from 'vitest';
import { parseSyncRaw } from './bindings.mjs';
import { parseAsync, parseSync } from './index.mjs';
import { parseSyncRaw } from './src-js/bindings.mjs';
import { parseAsync, parseSync } from './src-js/index.mjs';

// Internals
import { DATA_POINTER_POS_32, PROGRAM_OFFSET } from './generated/constants.mjs';
import { deserialize as deserializeJS } from './generated/deserialize/js.mjs';
import { deserialize as deserializeTS } from './generated/deserialize/ts.mjs';
import { walkProgram } from './generated/lazy/walk.mjs';
import { isJsAst, prepareRaw, returnBufferToCache } from './raw-transfer/common.mjs';
import { TOKEN } from './raw-transfer/lazy-common.mjs';
import { getVisitorsArr, Visitor } from './raw-transfer/visitor.mjs';
import { isJsAst, prepareRaw, returnBufferToCache } from './src-js/raw-transfer/common.mjs';
import { TOKEN } from './src-js/raw-transfer/lazy-common.mjs';
import { getVisitorsArr, Visitor } from './src-js/raw-transfer/visitor.mjs';

// Same fixtures as used in Rust parser benchmarks
let fixtureUrls = [
Expand Down
4 changes: 2 additions & 2 deletions napi/parser/build-browser-bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ async function main() {

// bundle wasm.mjs -> browser-bundle.mjs
await esbuild.build({
entryPoints: ['./wasm.mjs'],
entryPoints: ['./src-js/wasm.mjs'],
outfile: 'browser-bundle.mjs',
alias: {
'@oxc-parser/binding-wasm32-wasi': './parser.wasi-browser.js',
'@oxc-parser/binding-wasm32-wasi': './src-js/parser.wasi-browser.js',
},
bundle: true,
platform: 'browser',
Expand Down
2 changes: 1 addition & 1 deletion napi/parser/example.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import { parseArgs } from 'node:util';
import { parseSync } from './index.mjs';
import { parseSync } from './src-js/index.mjs';

// usage:
// node napi/parser/example.mjs test.ts
Expand Down
4 changes: 2 additions & 2 deletions napi/parser/generated/lazy/constructors.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/raw_transfer_lazy.rs`.

import { constructorError, TOKEN } from '../../raw-transfer/lazy-common.mjs';
import { NodeArray } from '../../raw-transfer/node-array.mjs';
import { constructorError, TOKEN } from '../../src-js/raw-transfer/lazy-common.mjs';
import { NodeArray } from '../../src-js/raw-transfer/node-array.mjs';

const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true }),
decodeStr = textDecoder.decode.bind(textDecoder),
Expand Down
31 changes: 7 additions & 24 deletions napi/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "oxc-parser",
"version": "0.90.0",
"type": "commonjs",
"main": "index.mjs",
"browser": "wasm.mjs",
"main": "src-js/index.mjs",
"browser": "src-js/wasm.mjs",
"scripts": {
"build-dev": "napi build --esm --platform --js bindings.mjs",
"build-dev": "napi build --esm --platform --js bindings.mjs --output-dir src-js",
"build-test": "pnpm run build-dev --profile coverage",
"build": "pnpm run build-dev --features allocator --release",
"postbuild-dev": "node patch.mjs",
"build-wasi": "pnpm run build-dev --release --target wasm32-wasip1-threads",
"build-npm-dir": "rm -rf npm-dir && napi create-npm-dirs --npm-dir npm-dir && pnpm napi artifacts --npm-dir npm-dir --output-dir .",
"build-npm-dir": "rm -rf npm-dir && napi create-npm-dirs --npm-dir npm-dir && pnpm napi artifacts --npm-dir npm-dir --output-dir src-js",
"build-browser-bundle": "node build-browser-bundle.mjs",
"test": "tsc && pnpm run test-node run",
"test-node": "vitest --dir ./test",
Expand Down Expand Up @@ -38,25 +38,8 @@
"url": "https://github.com/sponsors/Boshen"
},
"files": [
"index.d.ts",
"index.mjs",
"wrap.mjs",
"wasm.mjs",
"bindings.mjs",
"webcontainer-fallback.js",
"generated/constants.mjs",
"generated/deserialize/js.mjs",
"generated/deserialize/ts.mjs",
"generated/lazy/constructors.mjs",
"generated/lazy/types.mjs",
"generated/lazy/walk.mjs",
"raw-transfer/common.mjs",
"raw-transfer/eager.mjs",
"raw-transfer/lazy.mjs",
"raw-transfer/lazy-common.mjs",
"raw-transfer/node-array.mjs",
"raw-transfer/supported.mjs",
"raw-transfer/visitor.mjs"
"generated",
"src-js"
],
"publishConfig": {
"registry": "https://registry.npmjs.org/",
Expand Down Expand Up @@ -100,6 +83,6 @@
"fs": false
}
},
"dtsHeaderFile": "header.js"
"dtsHeaderFile": "src-js/header.js"
}
}
2 changes: 1 addition & 1 deletion napi/parser/patch.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'node:fs';

const filename = './bindings.mjs';
const filename = './src-js/bindings.mjs';
let data = fs.readFileSync(filename, 'utf-8');

data = data.replace(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os from 'node:os';
import { BUFFER_ALIGN, BUFFER_SIZE, IS_TS_FLAG_POS } from '../../generated/constants.mjs';
import {
getBufferOffset,
parseAsyncRaw as parseAsyncRawBinding,
parseSyncRaw as parseSyncRawBinding,
} from '../bindings.mjs';
import { BUFFER_ALIGN, BUFFER_SIZE, IS_TS_FLAG_POS } from '../generated/constants.mjs';
import { rawTransferSupported } from './supported.mjs';

// Throw an error if running on a platform which raw transfer doesn't support.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function deserialize(buffer, sourceText, sourceByteLen) {
// Lazy load deserializer, and deserialize buffer to JS objects
let data;
if (isJsAst(buffer)) {
if (deserializeJS === null) deserializeJS = require('../generated/deserialize/js.mjs').deserialize;
if (deserializeJS === null) deserializeJS = require('../../generated/deserialize/js.mjs').deserialize;

// `preserveParens` argument is unconditionally `true` here. If `options` contains `preserveParens: false`,
// `ParenthesizedExpression` nodes won't be in AST anyway, so the value is irrelevant.
Expand All @@ -67,7 +67,7 @@ function deserialize(buffer, sourceText, sourceByteLen) {
data.comments.unshift({ type: 'Line', value: hashbang.value, start: hashbang.start, end: hashbang.end });
}
} else {
if (deserializeTS === null) deserializeTS = require('../generated/deserialize/ts.mjs').deserialize;
if (deserializeTS === null) deserializeTS = require('../../generated/deserialize/ts.mjs').deserialize;

// `preserveParens` argument is unconditionally `true` here. If `options` contains `preserveParens: false`,
// `ParenthesizedExpression` nodes won't be in AST anyway, so the value is irrelevant.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DATA_POINTER_POS_32, PROGRAM_OFFSET } from '../generated/constants.mjs';
import { RawTransferData } from '../generated/lazy/constructors.mjs';
import { walkProgram } from '../generated/lazy/walk.mjs';
import { DATA_POINTER_POS_32, PROGRAM_OFFSET } from '../../generated/constants.mjs';
import { RawTransferData } from '../../generated/lazy/constructors.mjs';
import { walkProgram } from '../../generated/lazy/walk.mjs';
import { parseAsyncRawImpl, parseSyncRawImpl, returnBufferToCache } from './common.mjs';
import { TOKEN } from './lazy-common.mjs';
import { getVisitorsArr } from './visitor.mjs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LEAF_NODE_TYPES_COUNT, NODE_TYPE_IDS_MAP, NODE_TYPES_COUNT } from '../generated/lazy/types.mjs';
import { LEAF_NODE_TYPES_COUNT, NODE_TYPE_IDS_MAP, NODE_TYPES_COUNT } from '../../generated/lazy/types.mjs';

// Getter for private `#visitorsArr` property of `Visitor` class. Initialized in class body below.
let getVisitorsArrTemp;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion napi/parser/test-browser/parse.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from 'vitest';
import { parseAsync, parseSync } from '../wasm.mjs';
import { parseAsync, parseSync } from '../src-js/wasm.mjs';

test('parseSync', () => {
const result = parseSync('test.js', 'ok');
Expand Down
2 changes: 1 addition & 1 deletion napi/parser/test/esm.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from 'vitest';

import { parseSync } from '../index.mjs';
import { parseSync } from '../src-js/index.mjs';

describe('esm', () => {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#syntax
Expand Down
2 changes: 1 addition & 1 deletion napi/parser/test/lazy-deserialization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { describe, expect, it } from 'vitest';

import { parseSync } from '../index.mjs';
import { parseSync } from '../src-js/index.mjs';

function parseSyncLazy(filename, code, options = null) {
return parseSync(filename, code, { ...options, experimentalLazy: true });
Expand Down
2 changes: 1 addition & 1 deletion napi/parser/test/parse-raw-worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { readFile } from 'node:fs/promises';
import { basename, join as pathJoin } from 'node:path';

import { parseSync } from '../index.mjs';
import { parseSync } from '../src-js/index.mjs';
import {
ACORN_TEST262_DIR_PATH,
JSX_DIR_PATH,
Expand Down
2 changes: 1 addition & 1 deletion napi/parser/test/parse-raw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { basename, join as pathJoin } from 'node:path';
import Tinypool from 'tinypool';
import { describe, expect, it } from 'vitest';

import { parseAsync, parseSync } from '../index.mjs';
import { parseAsync, parseSync } from '../src-js/index.mjs';

import {
ACORN_TEST262_DIR_PATH,
Expand Down
9 changes: 7 additions & 2 deletions napi/parser/test/parse.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Worker } from 'node:worker_threads';
import { describe, expect, it, test } from 'vitest';

import { parseAsync, parseSync } from '../index.mjs';
import type { ExpressionStatement, ParserOptions, TSTypeAliasDeclaration, VariableDeclaration } from '../index.mjs';
import { parseAsync, parseSync } from '../src-js/index.mjs';
import type {
ExpressionStatement,
ParserOptions,
TSTypeAliasDeclaration,
VariableDeclaration,
} from '../src-js/index.mjs';

describe('parse', () => {
const code = '/* comment */ foo';
Expand Down
4 changes: 2 additions & 2 deletions napi/parser/test/parser.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertType, describe, it } from 'vitest';

import type { Node, Statement } from '../index';
import { parseSync } from '../index';
import type { Node, Statement } from '../src-js/index.mjs';
import { parseSync } from '../src-js/index.mjs';

describe('parse', () => {
const code = '/* comment */ foo';
Expand Down
2 changes: 1 addition & 1 deletion napi/parser/test/worker.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { parseSync } from '../index.mjs';
import { parseSync } from '../src-js/index.mjs';
parseSync('test.js', '');
2 changes: 1 addition & 1 deletion napi/playground/patch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let data = fs.readFileSync(filename, 'utf-8');
data = data.replace(
`export const Oxc = __napiModule.exports.Oxc`,
`
import { jsonParseAst } from "../parser/wrap.mjs"
import { jsonParseAst } from "../parser/src-js/wrap.mjs"

export function Oxc() {
const oxc = new __napiModule.exports.Oxc();
Expand Down
2 changes: 1 addition & 1 deletion napi/playground/playground.wasi-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const {
export default __napiModule.exports
export const Severity = __napiModule.exports.Severity

import { jsonParseAst } from "../parser/wrap.mjs"
import { jsonParseAst } from "../parser/src-js/wrap.mjs"

export function Oxc() {
const oxc = new __napiModule.exports.Oxc();
Expand Down
4 changes: 2 additions & 2 deletions tasks/ast_tools/src/generators/raw_transfer_lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ fn generate(
let constructors = &state.constructors;
#[rustfmt::skip]
let constructors = format!("
import {{ TOKEN, constructorError }} from '../../raw-transfer/lazy-common.mjs';
import {{ NodeArray }} from '../../raw-transfer/node-array.mjs';
import {{ constructorError, TOKEN }} from '../../src-js/raw-transfer/lazy-common.mjs';
import {{ NodeArray }} from '../../src-js/raw-transfer/node-array.mjs';

const textDecoder = new TextDecoder('utf-8', {{ ignoreBOM: true }}),
decodeStr = textDecoder.decode.bind(textDecoder),
Expand Down
Loading