fix(core): inheritance delegate ctor regex updated to work on minified code (#36962)
If one component Parent inherit another component Base like the following: @Component(...) class Base { constructor(@Inject(InjectionToken) injector: Injector) { } } @Component(...) class Parent extends Base { // no constructor } When creating Component Parent, the dependency injection should work on delegating ctors like above. The code Parent code above will be compiled into something like: class Parent extends Base { constructor() { super(...arguments); } } The angular core isDelegateCtor function will identify the delegation ctor to the base class. But when the code above is minified (using terser), the minified code will compress the spaces, resulting in something like: class Parent extends Base{constructor(){super(...arguments)}} The regex will stop working, since it wasn't aware of this case. So this fix will allow this to work in minified code cases. PR Close #36962
This commit is contained in:
parent
ddaa124162
commit
ea971f7098
|
@ -25,7 +25,7 @@ export const INHERITED_CLASS = /^class\s+[A-Za-z\d$_]*\s*extends\s+[^{]+{/;
|
|||
export const INHERITED_CLASS_WITH_CTOR =
|
||||
/^class\s+[A-Za-z\d$_]*\s*extends\s+[^{]+{[\s\S]*constructor\s*\(/;
|
||||
export const INHERITED_CLASS_WITH_DELEGATE_CTOR =
|
||||
/^class\s+[A-Za-z\d$_]*\s*extends\s+[^{]+{[\s\S]*constructor\s*\(\)\s*{\s+super\(\.\.\.arguments\)/;
|
||||
/^class\s+[A-Za-z\d$_]*\s*extends\s+[^{]+{[\s\S]*constructor\s*\(\)\s*{\s*super\(\.\.\.arguments\)/;
|
||||
|
||||
/**
|
||||
* Determine whether a stringified type is a class which delegates its constructor
|
||||
|
|
|
@ -201,6 +201,18 @@ class TestObj {
|
|||
expect(isDelegateCtor(ChildWithCtor.toString())).toBe(false);
|
||||
});
|
||||
|
||||
it('should support ES2015 classes when minified', () => {
|
||||
// These classes are ES2015 in minified form
|
||||
const ChildNoCtorMinified = 'class ChildNoCtor extends Parent{}';
|
||||
const ChildWithCtorMinified = 'class ChildWithCtor extends Parent{constructor(){super()}}';
|
||||
const ChildNoCtorPrivatePropsMinified =
|
||||
'class ChildNoCtorPrivateProps extends Parent{constructor(){super(...arguments);this.x=10}}';
|
||||
|
||||
expect(isDelegateCtor(ChildNoCtorMinified)).toBe(true);
|
||||
expect(isDelegateCtor(ChildNoCtorPrivatePropsMinified)).toBe(true);
|
||||
expect(isDelegateCtor(ChildWithCtorMinified)).toBe(false);
|
||||
});
|
||||
|
||||
it('should not throw when no prototype on type', () => {
|
||||
// Cannot test arrow function here due to the compilation
|
||||
const dummyArrowFn = function() {};
|
||||
|
|
Loading…
Reference in New Issue