Set parseOptions everywhere
MODIFY
packages/@romejs/core/common/bridges/WorkerBridge.ts
packages/@romejs/core/common/bridges/WorkerBridge.ts
@@ -44,7 +44,9 @@ export type WorkerPartialManifests = Array<{
}>;
// Omit analyze value as the worker will fetch it itself, skips sending over a large payload that it already has in memory
-export type WorkerCompilerOptions = {bundle?: WorkerBundleCompileOptions};
+export type WorkerCompilerOptions = {
+ bundle?: WorkerBundleCompileOptions;
+};
export type WorkerBundleCompileOptions = Omit<BundleCompileOptions, 'analyze'>;
@@ -53,11 +55,7 @@ export type WorkerAnalyzeDependencyResult = AnalyzeDependencyResult & {
cached: boolean;
};
-export type WorkerFormatOptions = {
- allowParserDiagnostics: boolean;
-};
-
-export type WorkerLintOptions = WorkerFormatOptions & {
+export type WorkerLintOptions = {
prefetchedModuleSignatures: PrefetchedModuleSignatures;
fix: boolean;
};
@@ -66,7 +64,7 @@ export type WorkerParseOptions = {
sourceType?: ConstSourceType;
syntax?: Array<ConstProgramSyntax>;
cache?: boolean;
- allowDiagnostics?: boolean;
+ allowParserDiagnostics?: boolean;
};
export type WorkerStatus = {
@@ -149,24 +147,24 @@ export default class WorkerBridge extends Bridge {
format = this.createEvent<{
file: JSONFileReference;
- options: WorkerFormatOptions;
+ parseOptions: WorkerParseOptions;
}, undefined | WorkerFormatResult>({
name: 'format',
direction: 'server->client',
});
- moduleSignatureJS = this.createEvent<
- {file: JSONFileReference},
- ModuleSignature
- >({
+ moduleSignatureJS = this.createEvent<{
+ file: JSONFileReference;
+ parseOptions: WorkerParseOptions;
+ }, ModuleSignature>({
name: 'moduleSignatureJS',
direction: 'server->client',
});
- analyzeDependencies = this.createEvent<
- {file: JSONFileReference},
- AnalyzeDependencyResult
- >({
+ analyzeDependencies = this.createEvent<{
+ file: JSONFileReference;
+ parseOptions: WorkerParseOptions;
+ }, AnalyzeDependencyResult>({
name: 'analyzeDependencies',
direction: 'server->client',
});
@@ -174,17 +172,19 @@ export default class WorkerBridge extends Bridge {
lint = this.createEvent<{
file: JSONFileReference;
options: WorkerLintOptions;
+ parseOptions: WorkerParseOptions;
}, WorkerLintResult>({name: 'lint', direction: 'server->client'});
compileJS = this.createEvent<{
file: JSONFileReference;
stage: TransformStageName;
options: WorkerCompilerOptions;
+ parseOptions: WorkerParseOptions;
}, CompileResult>({name: 'compileJS', direction: 'server->client'});
parseJS = this.createEvent<{
file: JSONFileReference;
- opts: WorkerParseOptions;
+ options: WorkerParseOptions;
}, Program>({name: 'parseJS', direction: 'server->client'});
updateBuffer = this.createEvent<{

MODIFY
packages/@romejs/core/common/fileHandlers.ts
packages/@romejs/core/common/fileHandlers.ts
import {ProjectConfig} from '@romejs/project';
import {FileReference} from '@romejs/core';
import {
- WorkerFormatOptions,
+ WorkerParseOptions,
WorkerLintOptions,
} from '../common/bridges/WorkerBridge';
import Worker, {ParseResult} from '../worker/Worker';
@@ -76,10 +76,6 @@ export function getFileHandlerAssert(
}
}
-export type ExtensionFormatInfo = ExtensionHandlerMethodInfo & {
- options: WorkerFormatOptions;
-};
-
export type ExtensionLintInfo = ExtensionHandlerMethodInfo & {
options: WorkerLintOptions;
format: boolean;
@@ -93,6 +89,7 @@ export type ExtensionLintResult = {
};
export type ExtensionHandlerMethodInfo = {
+ parseOptions: WorkerParseOptions;
file: FileReference;
project: compiler.TransformProjectDefinition;
worker: Worker;
@@ -105,7 +102,7 @@ export type ExtensionHandler = {
isAsset?: boolean;
canHaveScale?: boolean;
lint?: (info: ExtensionLintInfo) => Promise<ExtensionLintResult>;
- format?: (info: ExtensionFormatInfo) => Promise<ExtensionLintResult>;
+ format?: (info: ExtensionHandlerMethodInfo) => Promise<ExtensionLintResult>;
toJavaScript?: (opts: ExtensionHandlerMethodInfo) => Promise<{
generated: boolean;
sourceText: string;
@@ -280,8 +277,11 @@ function buildJSHandler(
syntax,
sourceType,
- async analyzeDependencies({file, worker}) {
- const {ast, sourceText, project, generated} = await worker.parseJS(file);
+ async analyzeDependencies({file, worker, parseOptions}) {
+ const {ast, sourceText, project, generated} = await worker.parseJS(
+ file,
+ parseOptions,
+ );
worker.logger.info(`Analyzing:`, file.real);
return worker.api.interceptAndAddGeneratedToDiagnostics(
@@ -305,10 +305,11 @@ function buildJSHandler(
async format(
info: ExtensionHandlerMethodInfo,
): Promise<ExtensionLintResult> {
- const {file: ref, worker} = info;
+ const {file: ref, parseOptions, worker} = info;
const {ast, sourceText, generated}: ParseResult = await worker.parseJS(
ref,
+ parseOptions,
);
const res = formatJS(ast, {
@@ -325,10 +326,11 @@ function buildJSHandler(
},
async lint(info: ExtensionLintInfo): Promise<ExtensionLintResult> {
- const {file: ref, project, format, options, worker} = info;
+ const {file: ref, project, format, parseOptions, options, worker} = info;
const {ast, sourceText, generated}: ParseResult = await worker.parseJS(
ref,
+ parseOptions,
);
worker.logger.info(`Linting: `, ref.real);
@@ -357,6 +359,7 @@ function buildJSHandler(
const typeCheckProvider = await worker.getTypeCheckProvider(
ref.project,
options.prefetchedModuleSignatures,
+ parseOptions,
);
const typeDiagnostics = await typeCheck({
ast,

MODIFY
packages/@romejs/core/master/MasterRequest.ts
packages/@romejs/core/master/MasterRequest.ts
@@ -57,7 +57,6 @@ import WorkerBridge, {
WorkerCompilerOptions,
WorkerFormatResult,
WorkerLintResult,
- WorkerFormatOptions,
WorkerLintOptions,
} from '../common/bridges/WorkerBridge';
import {ModuleSignature} from '@romejs/js-analysis';
@@ -777,13 +776,15 @@ export default class MasterRequest {
return this.wrapRequestDiagnostic(
'parse',
path,
- (bridge, file) => bridge.parseJS.call({file, opts}),
+ (bridge, file) => bridge.parseJS.call({file, options: opts}),
);
}
async requestWorkerLint(
path: AbsoluteFilePath,
optionsWithoutModSigs: Omit<WorkerLintOptions, 'prefetchedModuleSignatures'>,
+
+ parseOptions: WorkerParseOptions,
): Promise<
WorkerLintResult
> {
@@ -805,7 +806,7 @@ export default class MasterRequest {
const res = await this.wrapRequestDiagnostic(
'lint',
path,
- (bridge, file) => bridge.lint.call({file, options}),
+ (bridge, file) => bridge.lint.call({file, options, parseOptions}),
);
await cache.update(path, {
@@ -817,19 +818,20 @@ export default class MasterRequest {
async requestWorkerFormat(
path: AbsoluteFilePath,
- options: WorkerFormatOptions,
+ parseOptions: WorkerParseOptions,
): Promise<undefined | WorkerFormatResult> {
return await this.wrapRequestDiagnostic(
'format',
path,
- (bridge, file) => bridge.format.call({file, options}),
+ (bridge, file) => bridge.format.call({file, parseOptions}),
);
}
async requestWorkerCompile(
path: AbsoluteFilePath,
stage: TransformStageName,
- options?: WorkerCompilerOptions,
+ options: WorkerCompilerOptions,
+ parseOptions: WorkerParseOptions,
): Promise<WorkerCompileResult> {
const {cache} = this.master;
@@ -856,7 +858,7 @@ export default class MasterRequest {
options = {};
}
- return bridge.compileJS.call({file, stage, options});
+ return bridge.compileJS.call({file, stage, options, parseOptions});
});
const res = this.normalizeCompileResult({
@@ -880,6 +882,7 @@ export default class MasterRequest {
async requestWorkerAnalyzeDependencies(
path: AbsoluteFilePath,
+ parseOptions: WorkerParseOptions,
): Promise<WorkerAnalyzeDependencyResult> {
const {cache} = this.master;
@@ -891,7 +894,7 @@ export default class MasterRequest {
const res = await this.wrapRequestDiagnostic('analyzeDependencies', path, (
bridge,
file,
- ) => bridge.analyzeDependencies.call({file}));
+ ) => bridge.analyzeDependencies.call({file, parseOptions}));
await cache.update(path, {
analyzeDependencies: {
...res,
@@ -907,6 +910,7 @@ export default class MasterRequest {
async requestWorkerModuleSignature(
path: AbsoluteFilePath,
+ parseOptions: WorkerParseOptions,
): Promise<ModuleSignature> {
const {cache} = this.master;
@@ -918,7 +922,7 @@ export default class MasterRequest {
const res = await this.wrapRequestDiagnostic('moduleSignature', path, (
bridge,
file,
- ) => bridge.moduleSignatureJS.call({file}));
+ ) => bridge.moduleSignatureJS.call({file, parseOptions}));
await cache.update(path, {
moduleSignature: res,
});

MODIFY
packages/@romejs/core/master/bundler/BundleRequest.ts
packages/@romejs/core/master/bundler/BundleRequest.ts
@@ -189,6 +189,7 @@ export default class BundleRequest {
{
bundle: opts,
},
+ {},
);
if (!res.cached) {

MODIFY
packages/@romejs/core/master/commands/_moduleSignature.ts
packages/@romejs/core/master/commands/_moduleSignature.ts
@@ -22,6 +22,6 @@ export default createMasterCommand({
...req.getResolverOptionsFromFlags(),
source: createUnknownFilePath(args[0]),
}, {location: req.getDiagnosticPointerFromFlags({type: 'arg', key: 0})});
- reporter.inspect(await req.requestWorkerModuleSignature(filename));
+ reporter.inspect(await req.requestWorkerModuleSignature(filename, {}));
},
});

MODIFY
packages/@romejs/core/master/commands/analyzeDependencies.ts
packages/@romejs/core/master/commands/analyzeDependencies.ts
@@ -43,7 +43,7 @@ export default createMasterCommand({
source: createUnknownFilePath(args[0]),
}, {location: req.getDiagnosticPointerFromFlags({type: 'arg', key: 0})});
- let res = await req.requestWorkerAnalyzeDependencies(filename);
+ let res = await req.requestWorkerAnalyzeDependencies(filename, {});
const {focusSource} = commandFlags;
if (focusSource !== undefined) {

MODIFY
packages/@romejs/core/master/commands/compile.ts
packages/@romejs/core/master/commands/compile.ts
@@ -40,7 +40,7 @@ export default createMasterCommand({
const bundler = Bundler.createFromMasterRequest(req);
res = await bundler.compile(resolved.path);
} else {
- res = await req.requestWorkerCompile(resolved.path, 'compile');
+ res = await req.requestWorkerCompile(resolved.path, 'compile', {}, {});
}
const {compiledCode, diagnostics, suppressions}: WorkerCompileResult = res;

MODIFY
packages/@romejs/core/master/commands/parse.ts
packages/@romejs/core/master/commands/parse.ts
@@ -42,7 +42,7 @@ export default createMasterCommand({
let ast = await req.requestWorkerParse(filename, {
sourceType: flags.sourceType,
- allowDiagnostics: flags.allowDiagnostics,
+ allowParserDiagnostics: flags.allowDiagnostics,
});
if (flags.compact) {

MODIFY
packages/@romejs/core/master/dependencies/DependencyGraph.ts
packages/@romejs/core/master/dependencies/DependencyGraph.ts
@@ -267,6 +267,7 @@ export default class DependencyGraph {
const res: WorkerAnalyzeDependencyResult = await this.request.requestWorkerAnalyzeDependencies(
path,
+ {},
);
const node = this.addNode(path, res);

MODIFY
packages/@romejs/core/master/linter/Linter.ts
packages/@romejs/core/master/linter/Linter.ts
@@ -172,8 +172,10 @@ class LintRunner {
fixed,
} = await this.request.requestWorkerLint(path, {
fix: this.fix,
+ }, {
// TODO add this option?
- allowParserDiagnostics: false,
+
+
});
processor.addSuppressions(suppressions);
processor.addDiagnostics(diagnostics);

MODIFY
packages/@romejs/core/master/lsp/LSPServer.ts
packages/@romejs/core/master/lsp/LSPServer.ts
@@ -478,7 +478,7 @@ export default class LSPServer {
return null;
}
- const res = await this.request.requestWorkerFormat(path);
+ const res = await this.request.requestWorkerFormat(path, {});
if (res === undefined) {
// Not a file we support formatting
return null;

MODIFY
packages/@romejs/core/worker/Worker.ts
packages/@romejs/core/worker/Worker.ts
@@ -147,13 +147,14 @@ export default class Worker {
convertTransportFileReference(payload.file),
payload.stage,
payload.options,
+ payload.parseOptions,
);
});
bridge.parseJS.subscribe((payload) => {
return this.api.parseJS(
convertTransportFileReference(payload.file),
- payload.opts,
+ payload.options,
);
});
@@ -161,20 +162,21 @@ export default class Worker {
return this.api.lint(
convertTransportFileReference(payload.file),
payload.options,
+ payload.parseOptions,
);
});
bridge.format.subscribe((payload) => {
return this.api.format(
convertTransportFileReference(payload.file),
- payload.options,
+ payload.parseOptions,
);
});
bridge.analyzeDependencies.subscribe((payload) => {
return this.api.analyzeDependencies(convertTransportFileReference(
payload.file,
- ));
+ ), payload.parseOptions);
});
bridge.evict.subscribe((payload) => {
@@ -185,7 +187,7 @@ export default class Worker {
bridge.moduleSignatureJS.subscribe((payload) => {
return this.api.moduleSignatureJS(convertTransportFileReference(
payload.file,
- ));
+ ), payload.parseOptions);
});
bridge.updateProjects.subscribe((payload) => {
@@ -225,6 +227,7 @@ export default class Worker {
async getTypeCheckProvider(
projectId: number,
prefetchedModuleSignatures: PrefetchedModuleSignatures = {},
+ parseOptions: WorkerParseOptions,
): Promise<TypeCheckProvider> {
const libs: Array<Program> = [];
@@ -261,7 +264,7 @@ export default class Worker {
case 'OWNED':
return this.api.moduleSignatureJS(convertTransportFileReference(
value.file,
- ));
+ ), parseOptions);
case 'POINTER':
return resolveGraph(value.key);
@@ -306,7 +309,7 @@ export default class Worker {
async parseJS(
ref: FileReference,
- opts: WorkerParseOptions = {},
+ options: WorkerParseOptions,
): Promise<ParseResult> {
const path = createAbsoluteFilePath(ref.real);
@@ -321,16 +324,16 @@ export default class Worker {
// Get syntax
let syntax: Array<ConstProgramSyntax> = [];
- if (opts.syntax !== undefined) {
- syntax = opts.syntax;
+ if (options.syntax !== undefined) {
+ syntax = options.syntax;
} else if (handler.syntax !== undefined) {
syntax = handler.syntax;
}
// Get source type
let sourceType: undefined | ConstSourceType;
- if (opts.sourceType !== undefined) {
- sourceType = opts.sourceType;
+ if (options.sourceType !== undefined) {
+ sourceType = options.sourceType;
} else if (handler.sourceType !== undefined) {
sourceType = handler.sourceType;
} else {
@@ -348,7 +351,7 @@ export default class Worker {
sourceType = 'module';
}
- const cacheEnabled = opts.cache !== false;
+ const cacheEnabled = options.cache !== false;
if (cacheEnabled) {
// Update the lastAccessed of the ast cache and return it, it will be evicted on
@@ -380,6 +383,7 @@ export default class Worker {
file: ref,
worker: this,
project,
+ parseOptions: options,
});
let manifestPath: undefined | string;
@@ -402,7 +406,7 @@ export default class Worker {
}
// Sometimes we may want to allow the "fixed" AST
- const allowDiagnostics = opts.allowDiagnostics === true;
+ const allowDiagnostics = options.allowParserDiagnostics === true;
if (!allowDiagnostics && ast.diagnostics.length > 0) {
throw new DiagnosticsError(
"AST diagnostics aren't allowed",

MODIFY
packages/@romejs/core/worker/WorkerAPI.ts
packages/@romejs/core/worker/WorkerAPI.ts
@@ -19,7 +19,6 @@ import {
WorkerCompilerOptions,
WorkerFormatResult,
WorkerLintResult,
- WorkerFormatOptions,
WorkerLintOptions,
} from '../common/bridges/WorkerBridge';
import Logger from '../common/utils/Logger';
@@ -89,20 +88,25 @@ export default class WorkerAPI {
}
}
- async moduleSignatureJS(ref: FileReference) {
- const {ast, project} = await this.worker.parseJS(ref);
+ async moduleSignatureJS(ref: FileReference, parseOptions: WorkerParseOptions) {
+ const {ast, project} = await this.worker.parseJS(ref, parseOptions);
this.logger.info(`Generating export types:`, ref.real);
return await jsAnalysis.getModuleSignature({
ast,
project,
- provider: await this.worker.getTypeCheckProvider(ref.project),
+ provider: await this.worker.getTypeCheckProvider(
+ ref.project,
+ {},
+ parseOptions,
+ ),
});
}
async analyzeDependencies(
ref: FileReference,
+ parseOptions: WorkerParseOptions,
): Promise<AnalyzeDependencyResult> {
const project = this.worker.getProject(ref.project);
const {handler} = getFileHandlerAssert(ref.real, project.config);
@@ -117,12 +121,14 @@ export default class WorkerAPI {
file: ref,
project,
worker: this.worker,
+ parseOptions,
});
}
async workerCompilerOptionsToCompilerOptions(
ref: FileReference,
workerOptions: WorkerCompilerOptions,
+ parseOptions: WorkerParseOptions,
): Promise<CompilerOptions> {
const {bundle, ...options} = workerOptions;
@@ -133,7 +139,7 @@ export default class WorkerAPI {
...options,
bundle: {
...bundle,
- analyze: await this.analyzeDependencies(ref),
+ analyze: await this.analyzeDependencies(ref, parseOptions),
},
};
}
@@ -142,19 +148,24 @@ export default class WorkerAPI {
async compileJS(
ref: FileReference,
stage: TransformStageName,
- workerOptions: WorkerCompilerOptions,
+ options: WorkerCompilerOptions,
+ parseOptions: WorkerParseOptions,
): Promise<CompileResult> {
- const {ast, project, sourceText, generated} = await this.worker.parseJS(ref);
+ const {ast, project, sourceText, generated} = await this.worker.parseJS(
+ ref,
+ parseOptions,
+ );
this.logger.info(`Compiling:`, ref.real);
- const options = await this.workerCompilerOptionsToCompilerOptions(
+ const compilerOptions = await this.workerCompilerOptionsToCompilerOptions(
ref,
- workerOptions,
+ options,
+ parseOptions,
);
return this.interceptAndAddGeneratedToDiagnostics(await compile({
ast,
sourceText,
- options,
+ options: compilerOptions,
project,
stage,
}), generated);
@@ -162,6 +173,7 @@ export default class WorkerAPI {
async parseJS(ref: FileReference, opts: WorkerParseOptions): Promise<Program> {
let {ast, generated} = await this.worker.parseJS(ref, {
+ ...opts,
sourceType: opts.sourceType,
cache: false,
});
@@ -171,7 +183,7 @@ export default class WorkerAPI {
async format(
ref: FileReference,
- opts: WorkerFormatOptions,
+ opts: WorkerParseOptions,
): Promise<undefined | WorkerFormatResult> {
const res = await this._format(ref, opts);
if (res === undefined) {
@@ -198,7 +210,7 @@ export default class WorkerAPI {
async _format(
ref: FileReference,
- options: WorkerFormatOptions,
+ parseOptions: WorkerParseOptions,
): Promise<undefined | ExtensionLintResult> {
const project = this.worker.getProject(ref.project);
this.logger.info(`Formatting:`, ref.real);
@@ -217,7 +229,7 @@ export default class WorkerAPI {
file: ref,
project,
worker: this.worker,
- options,
+ parseOptions,
});
return res;
@@ -226,6 +238,7 @@ export default class WorkerAPI {
async lint(
ref: FileReference,
options: WorkerLintOptions,
+ parseOptions: WorkerParseOptions,
): Promise<WorkerLintResult> {
const project = this.worker.getProject(ref.project);
this.logger.info(`Linting:`, ref.real);
@@ -248,7 +261,7 @@ export default class WorkerAPI {
message: 'Caught by WorkerAPI.lint',
}, () => {
if (lint === undefined) {
- return this._format(ref, options);
+ return this._format(ref, parseOptions);
} else {
return lint({
format: this.shouldFormat(ref),
@@ -256,6 +269,7 @@ export default class WorkerAPI {
project,
worker: this.worker,
options,
+ parseOptions,
});
}
});
@@ -300,7 +314,7 @@ export default class WorkerAPI {
// Relint this file without fixing it, we do this to prevent false positive error messages
return {
- ...(await this.lint(ref, {...options, fix: false})),
+ ...(await this.lint(ref, {...options, fix: false}, parseOptions)),
fixed: true,
};
}

Set parseOptions everywhere