2021-04-29 21:22:35 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
2024-09-20 15:23:15 +00:00
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
2021-04-29 21:22:35 +00:00
|
|
|
*/
|
2022-12-13 17:31:50 +00:00
|
|
|
import babel from '@babel/core';
|
2025-06-02 14:18:09 +00:00
|
|
|
import path from 'node:path';
|
2021-04-29 21:22:35 +00:00
|
|
|
|
|
|
|
|
describe('default babel plugin entry-point', () => {
|
2022-12-13 17:31:50 +00:00
|
|
|
it('should work as a Babel plugin using the module specifier', async () => {
|
|
|
|
|
const result = (await babel.transformAsync(
|
2021-04-29 21:22:35 +00:00
|
|
|
`
|
|
|
|
|
import * as i0 from "@angular/core";
|
|
|
|
|
|
|
|
|
|
export class MyMod {}
|
|
|
|
|
export class MyComponent {}
|
|
|
|
|
|
|
|
|
|
MyMod.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyMod, declarations: [MyComponent] });
|
|
|
|
|
`,
|
|
|
|
|
{
|
2025-06-02 14:18:09 +00:00
|
|
|
cwd: path.resolve('./packages/compiler-cli/linker/babel/test'),
|
|
|
|
|
plugins: ['@angular/compiler-cli/linker/babel'],
|
2021-04-29 21:22:35 +00:00
|
|
|
filename: 'test.js',
|
2022-12-13 17:31:50 +00:00
|
|
|
},
|
|
|
|
|
))!;
|
2021-04-29 21:22:35 +00:00
|
|
|
|
|
|
|
|
expect(result).not.toBeNull();
|
|
|
|
|
expect(result.code).not.toContain('ɵɵngDeclareNgModule');
|
|
|
|
|
expect(result.code).toContain('i0.ɵɵdefineNgModule');
|
|
|
|
|
expect(result.code).not.toMatch(/declarations:\s*\[MyComponent]/);
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-13 17:31:50 +00:00
|
|
|
it('should be configurable', async () => {
|
|
|
|
|
const result = (await babel.transformAsync(
|
2021-04-29 21:22:35 +00:00
|
|
|
`
|
|
|
|
|
import * as i0 from "@angular/core";
|
|
|
|
|
|
|
|
|
|
export class MyMod {}
|
|
|
|
|
export class MyComponent {}
|
|
|
|
|
|
|
|
|
|
MyMod.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyMod, declarations: [MyComponent] });
|
|
|
|
|
`,
|
|
|
|
|
{
|
2025-06-02 14:18:09 +00:00
|
|
|
cwd: path.resolve('./packages/compiler-cli/linker/babel/test'),
|
|
|
|
|
plugins: [['@angular/compiler-cli/linker/babel', {linkerJitMode: true}]],
|
2021-04-29 21:22:35 +00:00
|
|
|
filename: 'test.js',
|
2022-12-13 17:31:50 +00:00
|
|
|
},
|
|
|
|
|
))!;
|
2021-04-29 21:22:35 +00:00
|
|
|
|
|
|
|
|
expect(result).not.toBeNull();
|
|
|
|
|
expect(result.code).not.toContain('ɵɵngDeclareNgModule');
|
|
|
|
|
expect(result.code).toContain('i0.ɵɵdefineNgModule');
|
|
|
|
|
expect(result.code).toMatch(/declarations:\s*\[MyComponent]/);
|
|
|
|
|
});
|
|
|
|
|
});
|