From cd447011396f9e29519f59d032668966c746d3b1 Mon Sep 17 00:00:00 2001 From: Tim Kendrick Date: Tue, 12 Dec 2023 16:29:41 +0000 Subject: [PATCH] Infer TypeScript JSX syntax based on file extension --- packages/ast/src/types/transform.ts | 2 +- packages/codemod-utils/src/angularHelpers.ts | 6 +- packages/codemod-utils/src/transform/js.ts | 37 +++-- packages/codemod-utils/src/transform/vue.ts | 12 +- packages/codemod-utils/src/transformer.ts | 32 +++- packages/codemod-utils/src/types/transform.ts | 14 +- .../src/versions/31.0.0/codemod.test.ts | 21 +++ .../codemods/src/versions/31.0.0/codemod.ts | 2 +- .../migrate-legacy-column-api.test.ts | 72 +++------ ...migrate-legacy-js-grid-constructor.test.ts | 21 +-- .../rename-grid-api-methods.test.ts | 15 +- .../rename-grid-options.test.ts | 153 ++++++------------ 12 files changed, 180 insertions(+), 207 deletions(-) diff --git a/packages/ast/src/types/transform.ts b/packages/ast/src/types/transform.ts index a91741b1..f1c9802a 100644 --- a/packages/ast/src/types/transform.ts +++ b/packages/ast/src/types/transform.ts @@ -17,7 +17,7 @@ export interface AstTransformContext extends FileMeta } export interface FileMetadata { - filename: string | undefined; + filename: string; } export interface AstCliContext extends FsContext { diff --git a/packages/codemod-utils/src/angularHelpers.ts b/packages/codemod-utils/src/angularHelpers.ts index 8e3e4cb6..9296a992 100644 --- a/packages/codemod-utils/src/angularHelpers.ts +++ b/packages/codemod-utils/src/angularHelpers.ts @@ -46,7 +46,7 @@ export function parseAngularComponentTemplate( const templateSource = getAngularComponentMetadataTemplateSource(componentMetadata, context); if (!templateSource) return null; return parse(templateSource, { - filePath: filePath, + filePath, suppressParseErrors: false, }); } @@ -72,7 +72,7 @@ function getAngularComponentMetadataTemplateSource( // FIXME: confirm assumptions on what constitutes a valid Angular templateUrl // FIXME: warn when unable to load Angular component template if (!templateUrl || !templateUrl.startsWith('.')) return null; - const currentPath = context.filename ? path.dirname(context.filename) : '.'; + const currentPath = path.dirname(context.filename); const templatePath = path.join(currentPath, templateUrl); const templateSource = (() => { const { fs } = context.opts; @@ -82,7 +82,7 @@ function getAngularComponentMetadataTemplateSource( throw new Error( [ `Failed to load Angular component template: ${templatePath}`, - ...(context.filename ? [` in component ${context.filename}`] : []), + ` in component ${context.filename}`, ].join('\n'), { cause: error, diff --git a/packages/codemod-utils/src/transform/js.ts b/packages/codemod-utils/src/transform/js.ts index e4552499..486369e4 100644 --- a/packages/codemod-utils/src/transform/js.ts +++ b/packages/codemod-utils/src/transform/js.ts @@ -13,50 +13,59 @@ import { } from '@ag-grid-devtools/ast'; import { parse, print } from 'recast'; -import { type AstTransformOptions } from '../types'; +import { + type AstTransformJsOptions, + type AstTransformJsxOptions, + type AstTransformOptions, +} from '../types'; -const PARSER_PLUGINS: Array = ['jsx', 'typescript', 'decorators-legacy']; +const JS_PARSER_PLUGINS: Array = ['typescript', 'decorators-legacy']; +const JSX_PARSER_PLUGINS: Array = ['jsx', ...JS_PARSER_PLUGINS]; export function transformJsScriptFile( source: string, transforms: Array | AstTransformWithOptions>, - options: AstTransformOptions, + options: AstTransformOptions & AstTransformJsOptions & AstTransformJsxOptions, ): AstTransformResult { return transformJsFile(source, transforms, { ...options, - sourceType: options.sourceType || 'script', + sourceType: 'script', }); } export function transformJsModuleFile( source: string, transforms: Array | AstTransformWithOptions>, - options: AstTransformOptions, + options: AstTransformOptions & AstTransformJsOptions & AstTransformJsxOptions, ): AstTransformResult { return transformJsFile(source, transforms, { ...options, - sourceType: options.sourceType || 'module', + sourceType: 'module', }); } export function transformJsUnknownFile( source: string, transforms: Array | AstTransformWithOptions>, - options: AstTransformOptions, + options: AstTransformOptions & AstTransformJsOptions & AstTransformJsxOptions, ): AstTransformResult { return transformJsFile(source, transforms, { ...options, // Determine whether module/script based on file contents - sourceType: options.sourceType || 'unambiguous', + sourceType: 'unambiguous', }); } export function transformJsFile( source: string, transforms: Array | AstTransformWithOptions>, - options: AstTransformOptions & Required>, + options: AstTransformOptions & + AstTransformJsOptions & + AstTransformJsxOptions & + Required>, ): AstTransformResult { - const { applyDangerousEdits, fs, ...parserOptions } = options; + const { filename, applyDangerousEdits, fs, jsx, sourceType, js: parserOptions = {} } = options; + const defaultPlugins = jsx ? JSX_PARSER_PLUGINS : JS_PARSER_PLUGINS; // Attempt to determine input file line endings, defaulting to the operating system default const crlfLineEndings = source.includes('\r\n'); const lfLineEndings = !crlfLineEndings && source.includes('\n'); @@ -64,12 +73,14 @@ export function transformJsFile( // Parse the source AST const ast = parse(source, { parser: { - sourceFilename: parserOptions.sourceFilename, + sourceFilename: filename, parse(source: string): ReturnType { const { plugins } = parserOptions; return parseAst(source, { ...parserOptions, - plugins: plugins ? [...PARSER_PLUGINS, ...plugins] : PARSER_PLUGINS, + sourceType, + sourceFilename: filename, + plugins: plugins ? [...defaultPlugins, ...plugins] : defaultPlugins, tokens: true, }); }, @@ -78,7 +89,7 @@ export function transformJsFile( // Transform the AST const uniqueErrors = new Map(); const transformContext: AstTransformContext = { - filename: parserOptions.sourceFilename, + filename, opts: { applyDangerousEdits, warn(node: NodePath | null, message: string) { diff --git a/packages/codemod-utils/src/transform/vue.ts b/packages/codemod-utils/src/transform/vue.ts index 38b9bd13..84e96381 100644 --- a/packages/codemod-utils/src/transform/vue.ts +++ b/packages/codemod-utils/src/transform/vue.ts @@ -5,12 +5,12 @@ import { type AstTransformWithOptions, } from '@ag-grid-devtools/ast'; -import { type AstTransformOptions } from '../types'; +import { type AstTransformJsOptions, type AstTransformOptions } from '../types'; import { parseVueSfcComponent, + printVueTemplate, type AST, type VueTemplateNode, - printVueTemplate, } from '../vueHelpers'; import { transformJsFile } from './js'; @@ -28,7 +28,7 @@ export function transformVueSfcFile( | AstTransform | AstTransformWithOptions >, - options: AstTransformOptions, + options: AstTransformOptions & AstTransformJsOptions, ): AstTransformResult { // Extract the different sections of the SFC const component = parseVueSfcComponent(source); @@ -61,7 +61,11 @@ export function transformVueSfcFile( const [plugin, options] = Array.isArray(transform) ? transform : [transform, {}]; return [plugin, { ...options, ...vueTransformOptions }]; }), - { ...options, sourceType: options.sourceType || 'module' }, + { + ...options, + sourceType: 'module', + jsx: false, + }, ); // Determine whether the template has been updated within the transform const updatedTemplate = vueTransformOptions.vue && vueTransformOptions.vue.template; diff --git a/packages/codemod-utils/src/transformer.ts b/packages/codemod-utils/src/transformer.ts index efc2e66d..52ba83c7 100644 --- a/packages/codemod-utils/src/transformer.ts +++ b/packages/codemod-utils/src/transformer.ts @@ -12,24 +12,42 @@ import { transformJsUnknownFile, transformVueSfcFile, } from './transform'; -import { type AstTransformOptions } from './types'; +import { type AstTransformJsOptions, type AstTransformOptions } from './types'; export function transformFile( source: string, transforms: Array | AstTransformWithOptions>, - options: AstTransformOptions, + options: AstTransformOptions & AstTransformJsOptions, ): AstTransformResult { - const extension = extname(options.sourceFilename); + const extension = extname(options.filename); switch (extension) { - case '.cjs': - return transformJsScriptFile(source, transforms, options); case '.js': case '.jsx': - return transformJsUnknownFile(source, transforms, options); + return transformJsUnknownFile(source, transforms, { + // JSX syntax is a superset of JS syntax, so assume all JS input files potentially contain JSX + jsx: true, + ...options, + }); + case '.cjs': + return transformJsScriptFile(source, transforms, { + // JSX syntax is a superset of JS syntax, so assume all JS input files potentially contain JSX + jsx: true, + ...options, + }); case '.mjs': + return transformJsModuleFile(source, transforms, { + // JSX syntax is a superset of JS syntax, so assume all JS input files potentially contain JSX + jsx: true, + ...options, + }); case '.ts': case '.tsx': - return transformJsModuleFile(source, transforms, options); + return transformJsModuleFile(source, transforms, { + // See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-1-6.html#new-tsx-file-extension-and-as-operator + // Legacy TypeScript cast syntax conflicts with JSX syntax, so only enable JSX parsing for .tsx files + jsx: extension === '.tsx', + ...options, + }); case '.vue': return transformVueSfcFile(source, transforms, options); default: diff --git a/packages/codemod-utils/src/types/transform.ts b/packages/codemod-utils/src/types/transform.ts index e867ed00..85045110 100644 --- a/packages/codemod-utils/src/types/transform.ts +++ b/packages/codemod-utils/src/types/transform.ts @@ -1,11 +1,17 @@ -import { type ParserOptions } from '@ag-grid-devtools/ast'; +import { type FileMetadata, type ParserOptions } from '@ag-grid-devtools/ast'; import { type CodemodFsUtils } from '@ag-grid-devtools/types'; -export type AstTransformOptions = ParserOptions & - Required> & - AstTransformCliOptions; +export type AstTransformOptions = FileMetadata & AstTransformCliOptions; export interface AstTransformCliOptions { applyDangerousEdits: boolean; fs: CodemodFsUtils; } + +export interface AstTransformJsOptions { + js?: Omit; +} + +export interface AstTransformJsxOptions { + jsx: boolean; +} diff --git a/packages/codemods/src/versions/31.0.0/codemod.test.ts b/packages/codemods/src/versions/31.0.0/codemod.test.ts index 5a9e83fa..888bf9bf 100644 --- a/packages/codemods/src/versions/31.0.0/codemod.test.ts +++ b/packages/codemods/src/versions/31.0.0/codemod.test.ts @@ -167,6 +167,27 @@ describe('Retains line endings', () => { }); }); +test('Supports legacy TypeScript cast expressions in non-TSX files', () => { + const input = ` + import { Grid, GridOptions } from 'ag-grid-community'; + const options = { foo: true }; + new Grid(document.body, options); + `; + const expected = ` + import { GridOptions, createGrid } from 'ag-grid-community'; + const options = { foo: true }; + const optionsApi = createGrid(document.body, options); + `; + const actual = codemod( + { path: './input.ts', source: input }, + { + applyDangerousEdits: true, + fs: createFsHelpers(memfs), + }, + ); + expect(actual).toEqual({ source: expected, errors: [] }); +}); + function createFsHelpers(fs: typeof memfs): CodemodFsUtils { return { readFileSync, diff --git a/packages/codemods/src/versions/31.0.0/codemod.ts b/packages/codemods/src/versions/31.0.0/codemod.ts index 2c7e94d8..2c2cfc21 100644 --- a/packages/codemods/src/versions/31.0.0/codemod.ts +++ b/packages/codemods/src/versions/31.0.0/codemod.ts @@ -17,7 +17,7 @@ const codemod: Codemod = function transform( const { path, source } = file; const { applyDangerousEdits, fs } = options; return transformFile(source, transforms, { - sourceFilename: path, + filename: path, applyDangerousEdits: Boolean(applyDangerousEdits), fs, }); diff --git a/packages/codemods/src/versions/31.0.0/transform/migrate-legacy-column-api/migrate-legacy-column-api.test.ts b/packages/codemods/src/versions/31.0.0/transform/migrate-legacy-column-api/migrate-legacy-column-api.test.ts index 70f30e97..dc0fd96e 100644 --- a/packages/codemods/src/versions/31.0.0/transform/migrate-legacy-column-api/migrate-legacy-column-api.test.ts +++ b/packages/codemods/src/versions/31.0.0/transform/migrate-legacy-column-api/migrate-legacy-column-api.test.ts @@ -19,8 +19,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -34,8 +33,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -52,8 +50,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -70,8 +67,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -88,8 +84,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -106,8 +101,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -123,8 +117,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -138,8 +131,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -165,8 +157,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -184,8 +175,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -202,8 +192,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -217,8 +206,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -232,8 +220,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -250,8 +237,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -268,8 +254,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -286,8 +271,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -304,8 +288,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -319,8 +302,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -334,8 +316,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -352,8 +333,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -369,8 +349,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -384,8 +363,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -399,8 +377,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -417,8 +394,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyColumnApi], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); diff --git a/packages/codemods/src/versions/31.0.0/transform/migrate-legacy-js-grid-constructor/migrate-legacy-js-grid-constructor.test.ts b/packages/codemods/src/versions/31.0.0/transform/migrate-legacy-js-grid-constructor/migrate-legacy-js-grid-constructor.test.ts index 7f6c6508..e79103db 100644 --- a/packages/codemods/src/versions/31.0.0/transform/migrate-legacy-js-grid-constructor/migrate-legacy-js-grid-constructor.test.ts +++ b/packages/codemods/src/versions/31.0.0/transform/migrate-legacy-js-grid-constructor/migrate-legacy-js-grid-constructor.test.ts @@ -20,8 +20,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyJsGridConstructor], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -35,8 +34,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyJsGridConstructor], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -52,8 +50,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyJsGridConstructor], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -71,8 +68,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyJsGridConstructor], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -86,8 +82,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyJsGridConstructor], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -103,8 +98,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyJsGridConstructor], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -121,8 +115,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [migrateLegacyJsGridConstructor], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); diff --git a/packages/codemods/src/versions/31.0.0/transform/rename-grid-api-methods/rename-grid-api-methods.test.ts b/packages/codemods/src/versions/31.0.0/transform/rename-grid-api-methods/rename-grid-api-methods.test.ts index b84f9345..2cdade34 100644 --- a/packages/codemods/src/versions/31.0.0/transform/rename-grid-api-methods/rename-grid-api-methods.test.ts +++ b/packages/codemods/src/versions/31.0.0/transform/rename-grid-api-methods/rename-grid-api-methods.test.ts @@ -18,8 +18,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridApiMethods], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -33,8 +32,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridApiMethods], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -48,8 +46,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridApiMethods], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -63,8 +60,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridApiMethods], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -78,8 +74,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridApiMethods], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); diff --git a/packages/codemods/src/versions/31.0.0/transform/rename-grid-options/rename-grid-options.test.ts b/packages/codemods/src/versions/31.0.0/transform/rename-grid-options/rename-grid-options.test.ts index f4802613..78714928 100644 --- a/packages/codemods/src/versions/31.0.0/transform/rename-grid-options/rename-grid-options.test.ts +++ b/packages/codemods/src/versions/31.0.0/transform/rename-grid-options/rename-grid-options.test.ts @@ -20,8 +20,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -35,8 +34,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -51,8 +49,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -70,8 +67,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -88,8 +84,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -104,8 +99,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -122,8 +116,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -138,8 +131,7 @@ describe('transforms input files correctly', () => { const expected = readFileSync(outputPath, 'utf-8'); { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -158,8 +150,7 @@ describe('transforms input files correctly', () => { } { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: true, fs: createFsHelpers(memfs), }); @@ -174,8 +165,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -190,8 +180,7 @@ describe('transforms input files correctly', () => { const expected = readFileSync(outputPath, 'utf-8'); { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -234,8 +223,7 @@ describe('transforms input files correctly', () => { } { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: true, fs: createFsHelpers(memfs), }); @@ -250,8 +238,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -265,8 +252,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -280,8 +266,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -296,8 +281,7 @@ describe('transforms input files correctly', () => { const expected = readFileSync(outputPath, 'utf-8'); { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -316,8 +300,7 @@ describe('transforms input files correctly', () => { } { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: true, fs: createFsHelpers(memfs), }); @@ -333,8 +316,7 @@ describe('transforms input files correctly', () => { const expected = readFileSync(outputPath, 'utf-8'); { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -353,8 +335,7 @@ describe('transforms input files correctly', () => { } { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: true, fs: createFsHelpers(memfs), }); @@ -373,8 +354,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -391,8 +371,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -407,8 +386,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -422,8 +400,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -442,8 +419,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -460,8 +436,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -480,8 +455,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -498,8 +472,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -519,8 +492,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -537,8 +509,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -554,8 +525,7 @@ describe('transforms input files correctly', () => { const expected = readFileSync(outputPath, 'utf-8'); { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -574,8 +544,7 @@ describe('transforms input files correctly', () => { } { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: true, fs: createFsHelpers(memfs), }); @@ -591,8 +560,7 @@ describe('transforms input files correctly', () => { const expected = readFileSync(outputPath, 'utf-8'); { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -611,8 +579,7 @@ describe('transforms input files correctly', () => { } { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: true, fs: createFsHelpers(memfs), }); @@ -630,8 +597,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -645,8 +611,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -662,8 +627,7 @@ describe('transforms input files correctly', () => { const expected = readFileSync(outputPath, 'utf-8'); { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -683,8 +647,7 @@ describe('transforms input files correctly', () => { } { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: true, fs: createFsHelpers(memfs), }); @@ -701,8 +664,7 @@ describe('transforms input files correctly', () => { const expected = readFileSync(outputPath, 'utf-8'); { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -722,8 +684,7 @@ describe('transforms input files correctly', () => { } { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: true, fs: createFsHelpers(memfs), }); @@ -739,8 +700,7 @@ describe('transforms input files correctly', () => { const expected = readFileSync(outputPath, 'utf-8'); { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -760,8 +720,7 @@ describe('transforms input files correctly', () => { } { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: true, fs: createFsHelpers(memfs), }); @@ -782,8 +741,7 @@ describe('transforms input files correctly', () => { const inputPath = join(scenarioPath, 'input.component.ts'); const input = readFileSync(inputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -801,8 +759,7 @@ describe('transforms input files correctly', () => { const inputPath = join(scenarioPath, 'input.component.ts'); const input = readFileSync(inputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -827,8 +784,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -857,8 +813,7 @@ describe('transforms input files correctly', () => { }); const input = readFileSync(inputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -886,8 +841,7 @@ describe('transforms input files correctly', () => { }); const input = readFileSync(inputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -922,8 +876,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -951,8 +904,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -980,8 +932,7 @@ describe('transforms input files correctly', () => { const input = readFileSync(inputPath, 'utf-8'); const expected = readFileSync(outputPath, 'utf-8'); const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -1007,8 +958,7 @@ describe('transforms input files correctly', () => { const expected = readFileSync(outputPath, 'utf-8'); { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: false, fs: createFsHelpers(memfs), }); @@ -1042,8 +992,7 @@ describe('transforms input files correctly', () => { } { const actual = transformFile(input, [renameGridOptions], { - sourceFilename: inputPath, - sourceType: 'module', + filename: inputPath, applyDangerousEdits: true, fs: createFsHelpers(memfs), });