@@ -48,8 +48,7 @@ import {
48
48
SETTER_PREFIX ,
49
49
LibrarySymbols ,
50
50
CommonSymbols ,
51
- INDEX_SUFFIX ,
52
- LIBRARY_PREFIX
51
+ INDEX_SUFFIX
53
52
} from "./common" ;
54
53
55
54
import {
@@ -147,7 +146,8 @@ import {
147
146
148
147
nodeIsConstantValue ,
149
148
findDecorator ,
150
- FieldDeclaration
149
+ FieldDeclaration ,
150
+ FunctionDeclaration
151
151
} from "./ast" ;
152
152
153
153
import {
@@ -5716,10 +5716,11 @@ export class Compiler extends DiagnosticEmitter {
5716
5716
}
5717
5717
let parameterTypes = instance . signature . parameterTypes ;
5718
5718
let parameterNodes = instance . prototype . signatureNode . parameters ;
5719
+ assert ( parameterNodes . length == parameterTypes . length ) ;
5719
5720
let allOptionalsAreConstant = true ;
5720
5721
for ( let i = numArguments ; i < maxArguments ; ++ i ) {
5721
5722
let initializer = parameterNodes [ i ] . initializer ;
5722
- if ( ! ( initializer !== null && nodeIsConstantValue ( initializer . kind ) ) ) {
5723
+ if ( ! ( initializer && nodeIsConstantValue ( initializer . kind ) ) ) {
5723
5724
allOptionalsAreConstant = false ;
5724
5725
break ;
5725
5726
}
@@ -6653,22 +6654,38 @@ export class Compiler extends DiagnosticEmitter {
6653
6654
return instance ;
6654
6655
}
6655
6656
6656
- // use the signature of the parent constructor if a derived class
6657
+ // clone base constructor if a derived class
6657
6658
var baseClass = classInstance . base ;
6658
- var signature = baseClass
6659
- ? this . ensureConstructor ( baseClass , reportNode ) . signature
6660
- : new Signature ( null , classInstance . type , classInstance . type ) ;
6661
-
6662
- instance = new Function (
6663
- CommonSymbols . constructor ,
6664
- new FunctionPrototype ( CommonSymbols . constructor , classInstance ,
6665
- this . program . makeNativeFunctionDeclaration ( CommonSymbols . constructor ,
6666
- CommonFlags . INSTANCE | CommonFlags . CONSTRUCTOR
6667
- )
6668
- ) ,
6669
- signature ,
6670
- null
6671
- ) ;
6659
+ if ( baseClass ) {
6660
+ let baseCtor = this . ensureConstructor ( baseClass , reportNode ) ;
6661
+ instance = new Function (
6662
+ CommonSymbols . constructor ,
6663
+ new FunctionPrototype (
6664
+ CommonSymbols . constructor ,
6665
+ classInstance ,
6666
+ // declaration is important, i.e. to access optional parameter initializers
6667
+ ( < FunctionDeclaration > baseCtor . declaration ) . clone ( )
6668
+ ) ,
6669
+ baseCtor . signature ,
6670
+ null
6671
+ ) ;
6672
+
6673
+ // otherwise make a default constructor
6674
+ } else {
6675
+ instance = new Function (
6676
+ CommonSymbols . constructor ,
6677
+ new FunctionPrototype (
6678
+ CommonSymbols . constructor ,
6679
+ classInstance ,
6680
+ this . program . makeNativeFunctionDeclaration ( CommonSymbols . constructor ,
6681
+ CommonFlags . INSTANCE | CommonFlags . CONSTRUCTOR
6682
+ )
6683
+ ) ,
6684
+ new Signature ( null , classInstance . type , classInstance . type ) ,
6685
+ null
6686
+ ) ;
6687
+ }
6688
+
6672
6689
instance . internalName = classInstance . internalName + INSTANCE_DELIMITER + "constructor" ;
6673
6690
instance . set ( CommonFlags . COMPILED ) ;
6674
6691
instance . prototype . setResolvedInstance ( "" , instance ) ;
@@ -6677,6 +6694,7 @@ export class Compiler extends DiagnosticEmitter {
6677
6694
this . currentFlow = instance . flow ;
6678
6695
6679
6696
// generate body
6697
+ var signature = instance . signature ;
6680
6698
var module = this . module ;
6681
6699
var nativeSizeType = this . options . nativeSizeType ;
6682
6700
var stmts = new Array < ExpressionRef > ( ) ;
0 commit comments