Remove redundant compiler options and clean up result property names
MODIFY
packages/@romejs/core/master/bundler/BundleRequest.ts
packages/@romejs/core/master/bundler/BundleRequest.ts
@@ -302,8 +302,8 @@ export default class BundleRequest {
declareCJS(module);
- addMappings(module.id, compileResult.src, compileResult.mappings);
- push(compileResult.code);
+ addMappings(module.id, compileResult.sourceText, compileResult.mappings);
+ push(compileResult.compiledCode);
push('');
}

MODIFY
packages/@romejs/core/master/commands/compile.ts
packages/@romejs/core/master/commands/compile.ts
@@ -49,12 +49,12 @@ export default createMasterCommand({
res = await req.requestWorkerCompile(resolved.path, 'compile');
}
- const {code, diagnostics, filters}: WorkerCompileResult = res;
+ const {compiledCode, diagnostics, filters}: WorkerCompileResult = res;
if (diagnostics.length > 0) {
throw new DiagnosticsError('Compile diagnostics', diagnostics, filters);
}
- reporter.writeAll(code);
+ reporter.writeAll(compiledCode);
},
});

MODIFY
packages/@romejs/js-compiler/api/compile.ts
packages/@romejs/js-compiler/api/compile.ts
@@ -11,15 +11,14 @@ import {CompileRequest} from '../types';
import {Cache} from '@romejs/js-compiler';
import {generateJS} from '@romejs/js-generator';
import transform from '../methods/transform';
-import lint from './lint';
export type CompileResult = {
- code: string;
- src: string;
mappings: Mappings;
diagnostics: PartialDiagnostics;
filters: DiagnosticFilters;
cacheDependencies: Array<string>;
+ compiledCode: string;
+ sourceText: string;
};
const compileCache: Cache<CompileResult> = new Cache();
@@ -27,17 +26,7 @@ const compileCache: Cache<CompileResult> = new Cache();
export default async function compile(
req: CompileRequest,
): Promise<CompileResult> {
- let {ast} = req;
- const {sourceText: src} = req;
-
- // Option to allow linting before compiling
- let lintDiagnostics: PartialDiagnostics = [];
- if (req.lint === true) {
- ({ast, diagnostics: lintDiagnostics} = await lint(req));
- req = {...req, ast};
- } else {
- lintDiagnostics = ast.diagnostics;
- }
+ const {sourceText, ast} = req;
const query = Cache.buildQuery(req);
const cached: undefined | CompileResult = compileCache.get(query);
@@ -61,17 +50,17 @@ export default async function compile(
sourceFileName: filename,
inputSourceMap: req.inputSourceMap,
},
- src,
+ sourceText,
);
- let res: CompileResult = {
- code: generator.getCode(),
+
+ const res: CompileResult = {
+ compiledCode: generator.getCode(),
mappings: generator.getMappings(),
- src,
- diagnostics: [...lintDiagnostics, ...diagnostics],
+ diagnostics: [...ast.diagnostics, ...diagnostics],
cacheDependencies,
filters,
+ sourceText,
};
compileCache.set(query, res);
-
return res;
}

MODIFY
packages/@romejs/js-compiler/api/lint.ts
packages/@romejs/js-compiler/api/lint.ts
* LICENSE file in the root directory of this source tree.
*/
-import {Program} from '@romejs/js-ast';
import {PartialDiagnostics, DiagnosticFilters} from '@romejs/diagnostics';
import {TransformRequest} from '../types';
import {lintTransforms} from '../transforms/lint/index';
@@ -23,14 +22,13 @@ export type LintResult = {
const lintCache: Cache<LintResult> = new Cache();
export default async function lint(req: TransformRequest): Promise<LintResult> {
- const {sourceText: src, project} = req;
- let {ast} = req;
+ const {ast, sourceText, project} = req;
if (!project.config.lint.enabled) {
return {
diagnostics: [],
filters: extractSuppressionsFromProgram(ast),
- src,
+ src: sourceText,
};
}
@@ -40,7 +38,7 @@ export default async function lint(req: TransformRequest): Promise<LintResult> {
return cached;
}
- let formattedCode = src;
+ let formattedCode = sourceText;
if (project.config.format.enabled) {
// Perform autofixes
const context = new Context({
@@ -59,7 +57,7 @@ export default async function lint(req: TransformRequest): Promise<LintResult> {
{
typeAnnotations: true,
},
- src,
+ sourceText,
);
formattedCode = generator.getCode() + '\n';
}

MODIFY
packages/@romejs/js-compiler/types.ts
packages/@romejs/js-compiler/types.ts
@@ -56,7 +56,6 @@ export type TransformVisitors = Array<TransformVisitor>;
export type CompileRequest = TransformRequest & {
inputSourceMap?: SourceMap;
- lint?: boolean;
};
export type TransformProjectDefinition = {

MODIFY
packages/rome/index.ts
packages/rome/index.ts
@@ -119,7 +119,7 @@ export const compile = wrapForErrors(async function(opts: {
return {
cacheKey,
- code: res.code,
+ code: res.compiledCode,
sourceMap,
};
});

Remove redundant compiler options and clean up result property names