Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: tweak the comment about files should not be edited #5463

Merged
merged 1 commit into from
Apr 10, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/parse_ast/src/convert_ast/converter/ast_constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is generated by scripts/generate-ast-converters.js.
// This file is generated by scripts/generate-rust-constants.js.
// Do not edit this file directly.

pub const TYPE_PANIC_ERROR: [u8; 4] = 0u32.to_ne_bytes();
Expand Down
3 changes: 2 additions & 1 deletion rust/parse_ast/src/convert_ast/converter/string_constants.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This file is generated by scripts/generate-string-constant.js.
// This file is generated by scripts/generate-string-constants.js.
// Do not edit this file directly.

pub const STRING_VAR: [u8; 4] = 0u32.to_ne_bytes(); // var
pub const STRING_LET: [u8; 4] = 1u32.to_ne_bytes(); // let
pub const STRING_CONST: [u8; 4] = 2u32.to_ne_bytes(); // const
Expand Down
8 changes: 4 additions & 4 deletions scripts/generate-buffer-parsers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { writeFile } from 'node:fs/promises';
import { astNodeNamesWithFieldOrder } from './ast-types.js';
import { firstLetterLowercase, lintTsFile } from './helpers.js';
import { firstLetterLowercase, generateNotEditFilesComment, lintTsFile } from './helpers.js';

const notEditFilesComment = generateNotEditFilesComment(import.meta.url);

const bufferParsersFile = new URL('../src/ast/bufferParsers.ts', import.meta.url);

Expand Down Expand Up @@ -168,9 +170,7 @@ function getFieldDefinition([fieldName, fieldType], node, originalNode, offset)
}
}

const bufferParsers = `// This file is generated by scripts/generate-ast-converters.js.
// Do not edit this file directly.

const bufferParsers = `${notEditFilesComment}
import type * as estree from 'estree';
import type { AstContext } from '../Module';
import { convertAnnotations, convertString } from '../utils/astConverterHelpers';
Expand Down
8 changes: 4 additions & 4 deletions scripts/generate-buffer-to-ast.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { writeFile } from 'node:fs/promises';
import { astNodeNamesWithFieldOrder } from './ast-types.js';
import { firstLetterLowercase, lintTsFile } from './helpers.js';
import { firstLetterLowercase, generateNotEditFilesComment, lintTsFile } from './helpers.js';

const notEditFilesComment = generateNotEditFilesComment(import.meta.url);

const bufferToJsAstFile = new URL('../src/utils/bufferToAst.ts', import.meta.url);

Expand Down Expand Up @@ -156,9 +158,7 @@ const types = astNodeNamesWithFieldOrder.map(({ name, node }) => {
return typeDefinition;
});

const bufferToJsAst = `// This file is generated by scripts/generate-ast-converters.js.
// Do not edit this file directly.

const bufferToJsAst = `${notEditFilesComment}
import type * as estree from 'estree';
import { PanicError, ParseError } from '../ast/nodes/NodeType';import type { RollupAstNode } from '../rollup/types';
import type { RollupAnnotation } from './astConverterHelpers';
Expand Down
8 changes: 4 additions & 4 deletions scripts/generate-child-node-keys.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { writeFile } from 'node:fs/promises';
import { AST_NODES } from './ast-types.js';
import { lintTsFile } from './helpers.js';
import { generateNotEditFilesComment, lintTsFile } from './helpers.js';

const notEditFilesComment = generateNotEditFilesComment(import.meta.url);

const childNodeKeysFile = new URL('../src/ast/childNodeKeys.ts', import.meta.url);

Expand All @@ -18,9 +20,7 @@ for (const [name, node] of Object.entries(AST_NODES)) {
}
}

const childNodeKeys = `// This file is generated by scripts/generate-ast-converters.js.
// Do not edit this file directly.

const childNodeKeys = `${notEditFilesComment}
export const childNodeKeys: Record<string, string[]> = {
${Object.entries(childNodeKeysByAstType)
.sort(([astType1], [astType2]) => astType1.localeCompare(astType2))
Expand Down
8 changes: 4 additions & 4 deletions scripts/generate-rust-constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { writeFile } from 'node:fs/promises';
import { AST_NODES, astNodeNamesWithFieldOrder } from './ast-types.js';
import { lintRustFile, toScreamingSnakeCase } from './helpers.js';
import { generateNotEditFilesComment, lintRustFile, toScreamingSnakeCase } from './helpers.js';

const BYTES_PER_U32 = 4;

const notEditFilesComment = generateNotEditFilesComment(import.meta.url);

const astConstantsFile = new URL(
'../rust/parse_ast/src/convert_ast/converter/ast_constants.rs',
import.meta.url
Expand Down Expand Up @@ -67,9 +69,7 @@ const reservedBytesAndOffsets = astNodeNamesWithFieldOrder
})
.join('\n');

const astConstants = `// This file is generated by scripts/generate-ast-converters.js.
// Do not edit this file directly.

const astConstants = `${notEditFilesComment}
${nodeTypes}

${reservedBytesAndOffsets}
Expand Down
11 changes: 5 additions & 6 deletions scripts/generate-string-constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { writeFile } from 'node:fs/promises';
import { lintRustFile, lintTsFile } from './helpers.js';
import { generateNotEditFilesComment, lintRustFile, lintTsFile } from './helpers.js';

const notEditFilesComment = generateNotEditFilesComment(import.meta.url);

const targetRustFile = new URL(
'../rust/parse_ast/src/convert_ast/converter/string_constants.rs',
Expand Down Expand Up @@ -73,11 +75,8 @@ const stringConstantsTemplate = [
['STRING_AWAIT_USING', 'await using']
];

const tipComment = `// This file is generated by scripts/generate-string-constant.js.
// Do not edit this file directly.\n`;

const rustCode =
tipComment +
notEditFilesComment +
stringConstantsTemplate
.map(
([variableName, value], index) =>
Expand All @@ -86,7 +85,7 @@ const rustCode =
.join('\n');

const tsCode =
tipComment +
notEditFilesComment +
`export default ` +
JSON.stringify(
stringConstantsTemplate.map(([, value]) => value),
Expand Down
10 changes: 10 additions & 0 deletions scripts/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { spawn } from 'node:child_process';
import { readFile } from 'node:fs/promises';
import { relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import { ESLint } from 'eslint';
import { blue, bold, cyan, green, magenta, red, yellow } from './colors.js';
Expand Down Expand Up @@ -112,3 +113,12 @@ export function firstLetterLowercase(string) {
export function toScreamingSnakeCase(string) {
return string.replace(/(?<!^)([A-Z])/g, '_$1').toUpperCase();
}

/**
* @param {string} filePath
* @returns {string}
*/
export function generateNotEditFilesComment(filePath) {
return `// This file is generated by ${relative(process.cwd(), fileURLToPath(filePath))}.
// Do not edit this file directly.\n\n`;
}
2 changes: 1 addition & 1 deletion src/ast/bufferParsers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is generated by scripts/generate-ast-converters.js.
// This file is generated by scripts/generate-buffer-parsers.js.
// Do not edit this file directly.

import type * as estree from 'estree';
Expand Down
2 changes: 1 addition & 1 deletion src/ast/childNodeKeys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is generated by scripts/generate-ast-converters.js.
// This file is generated by scripts/generate-child-node-keys.js.
// Do not edit this file directly.

export const childNodeKeys: Record<string, string[]> = {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/bufferToAst.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is generated by scripts/generate-ast-converters.js.
// This file is generated by scripts/generate-buffer-to-ast.js.
// Do not edit this file directly.

import type * as estree from 'estree';
Expand Down
3 changes: 2 additions & 1 deletion src/utils/convert-ast-strings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This file is generated by scripts/generate-string-constant.js.
// This file is generated by scripts/generate-string-constants.js.
// Do not edit this file directly.

export default [
'var',
'let',
Expand Down