fix(ngcc): render UMD imports even if no prior imports (#34353)
Previously the UMD rendering formatter assumed that there would already be import (and an export) arguments to the UMD factory function. This commit adds support for this corner case. Fixes #34138 PR Close #34353
This commit is contained in:

committed by
Kara Erickson

parent
241f948358
commit
c26738df12
@ -291,6 +291,40 @@ typeof define === 'function' && define.amd ? define('file', ['exports','/tslib',
|
||||
expect(output.toString())
|
||||
.toContain(`(function (exports,someSideEffect,localDep,core,i0,i1) {'use strict';`);
|
||||
});
|
||||
|
||||
it('should handle the case where there were no prior imports nor exports', () => {
|
||||
const PROGRAM: TestFile = {
|
||||
name: _('/node_modules/test-package/some/file.js'),
|
||||
contents: `
|
||||
/* A copyright notice */
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
|
||||
typeof define === 'function' && define.amd ? define('file', factory) :
|
||||
(factory());
|
||||
}(this, (function () {'use strict';
|
||||
var index = '';
|
||||
return index;
|
||||
})));`,
|
||||
};
|
||||
const {renderer, program} = setup(PROGRAM);
|
||||
const file = getSourceFileOrError(program, _('/node_modules/test-package/some/file.js'));
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
renderer.addImports(
|
||||
output,
|
||||
[
|
||||
{specifier: '@angular/core', qualifier: 'i0'},
|
||||
{specifier: '@angular/common', qualifier: 'i1'}
|
||||
],
|
||||
file);
|
||||
const outputSrc = output.toString();
|
||||
|
||||
expect(outputSrc).toContain(
|
||||
`typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('@angular/core'),require('@angular/common')) :`);
|
||||
expect(outputSrc).toContain(
|
||||
`typeof define === 'function' && define.amd ? define('file',['@angular/core','@angular/common'], factory) :`);
|
||||
expect(outputSrc).toContain(`(factory(global.ng.core,global.ng.common));`);
|
||||
expect(outputSrc).toContain(`(function (i0,i1) {'use strict';`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('addExports', () => {
|
||||
|
Reference in New Issue
Block a user