Skip to content

Commit e182ecf

Browse files
authored
Fix 8355: Fix emit metadata different between transpile and tsc --isolatedModule (#9232)
* Instead of returning undefined for unknownSymbol return itself * Add Transpile unittest * Wip - Add project tests * Add project tests and baselines * Update existed tests * Add tests for emitting metadata with module targetting system
1 parent fb3f823 commit e182ecf

File tree

50 files changed

+746
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+746
-2
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,9 +1265,13 @@ namespace ts {
12651265
const right = name.kind === SyntaxKind.QualifiedName ? (<QualifiedName>name).right : (<PropertyAccessExpression>name).name;
12661266

12671267
const namespace = resolveEntityName(left, SymbolFlags.Namespace, ignoreErrors);
1268-
if (!namespace || namespace === unknownSymbol || nodeIsMissing(right)) {
1268+
if (!namespace || nodeIsMissing(right)) {
12691269
return undefined;
12701270
}
1271+
else if (namespace === unknownSymbol) {
1272+
return namespace;
1273+
}
1274+
12711275
symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning);
12721276
if (!symbol) {
12731277
if (!ignoreErrors) {

tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision4.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ var MyClass = (function () {
4646
}
4747
MyClass = __decorate([
4848
someDecorator,
49-
__metadata('design:paramtypes', [Object])
49+
__metadata('design:paramtypes', [(typeof (_a = typeof db_1.default !== 'undefined' && db_1.default.db) === 'function' && _a) || Object])
5050
], MyClass);
5151
return MyClass;
52+
var _a;
5253
}());
5354
exports.MyClass = MyClass;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
main.ts(1,21): error TS2307: Cannot find module 'angular2/core'.
2+
3+
4+
==== main.ts (1 errors) ====
5+
import * as ng from "angular2/core";
6+
~~~~~~~~~~~~~~~
7+
!!! error TS2307: Cannot find module 'angular2/core'.
8+
9+
declare function foo(...args: any[]);
10+
11+
@foo
12+
export class MyClass1 {
13+
constructor(private _elementRef: ng.ElementRef){}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"scenario": "Emit decorator metadata when commonJS and isolatedModules are on",
3+
"projectRoot": "tests/cases/projects/decoratorMetadata/emitDecoratorMetadataCommonJSIsolatedModule",
4+
"baselineCheck": true,
5+
"runTest": true,
6+
"resolvedInputFiles": [
7+
"lib.d.ts",
8+
"main.ts"
9+
],
10+
"emittedFiles": [
11+
"main.js"
12+
]
13+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5+
return c > 3 && r && Object.defineProperty(target, key, r), r;
6+
};
7+
var __metadata = (this && this.__metadata) || function (k, v) {
8+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9+
};
10+
define(["require", "exports", "angular2/core"], function (require, exports, ng) {
11+
"use strict";
12+
var MyClass1 = (function () {
13+
function MyClass1(_elementRef) {
14+
this._elementRef = _elementRef;
15+
}
16+
MyClass1 = __decorate([
17+
foo,
18+
__metadata('design:paramtypes', [(typeof (_a = typeof ng !== 'undefined' && ng.ElementRef) === 'function' && _a) || Object])
19+
], MyClass1);
20+
return MyClass1;
21+
var _a;
22+
}());
23+
exports.MyClass1 = MyClass1;
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
main.ts(1,21): error TS2307: Cannot find module 'angular2/core'.
2+
3+
4+
==== main.ts (1 errors) ====
5+
import * as ng from "angular2/core";
6+
~~~~~~~~~~~~~~~
7+
!!! error TS2307: Cannot find module 'angular2/core'.
8+
9+
declare function foo(...args: any[]);
10+
11+
@foo
12+
export class MyClass1 {
13+
constructor(private _elementRef: ng.ElementRef){}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"scenario": "Emit decorator metadata when commonJS and isolatedModules are on",
3+
"projectRoot": "tests/cases/projects/decoratorMetadata/emitDecoratorMetadataCommonJSIsolatedModule",
4+
"baselineCheck": true,
5+
"runTest": true,
6+
"resolvedInputFiles": [
7+
"lib.d.ts",
8+
"main.ts"
9+
],
10+
"emittedFiles": [
11+
"main.js"
12+
]
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6+
return c > 3 && r && Object.defineProperty(target, key, r), r;
7+
};
8+
var __metadata = (this && this.__metadata) || function (k, v) {
9+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10+
};
11+
var ng = require("angular2/core");
12+
var MyClass1 = (function () {
13+
function MyClass1(_elementRef) {
14+
this._elementRef = _elementRef;
15+
}
16+
MyClass1 = __decorate([
17+
foo,
18+
__metadata('design:paramtypes', [(typeof (_a = typeof ng !== 'undefined' && ng.ElementRef) === 'function' && _a) || Object])
19+
], MyClass1);
20+
return MyClass1;
21+
var _a;
22+
}());
23+
exports.MyClass1 = MyClass1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
main.ts(1,21): error TS2307: Cannot find module 'angular2/core'.
2+
3+
4+
==== main.ts (1 errors) ====
5+
import * as ng from "angular2/core";
6+
~~~~~~~~~~~~~~~
7+
!!! error TS2307: Cannot find module 'angular2/core'.
8+
9+
declare function foo(...args: any[]);
10+
11+
@foo
12+
export class MyClass1 {
13+
constructor(private _elementRef: ng.ElementRef){}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"scenario": "Emit decorator metadata when commonJS and isolatedModules are on",
3+
"projectRoot": "tests/cases/projects/decoratorMetadata/emitDecoratorMetadataCommonJSIsolatedModuleNoResolve",
4+
"baselineCheck": true,
5+
"runTest": true,
6+
"resolvedInputFiles": [
7+
"lib.d.ts",
8+
"main.ts"
9+
],
10+
"emittedFiles": [
11+
"main.js"
12+
]
13+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5+
return c > 3 && r && Object.defineProperty(target, key, r), r;
6+
};
7+
var __metadata = (this && this.__metadata) || function (k, v) {
8+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9+
};
10+
define(["require", "exports", "angular2/core"], function (require, exports, ng) {
11+
"use strict";
12+
var MyClass1 = (function () {
13+
function MyClass1(_elementRef) {
14+
this._elementRef = _elementRef;
15+
}
16+
MyClass1 = __decorate([
17+
foo,
18+
__metadata('design:paramtypes', [(typeof (_a = typeof ng !== 'undefined' && ng.ElementRef) === 'function' && _a) || Object])
19+
], MyClass1);
20+
return MyClass1;
21+
var _a;
22+
}());
23+
exports.MyClass1 = MyClass1;
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
main.ts(1,21): error TS2307: Cannot find module 'angular2/core'.
2+
3+
4+
==== main.ts (1 errors) ====
5+
import * as ng from "angular2/core";
6+
~~~~~~~~~~~~~~~
7+
!!! error TS2307: Cannot find module 'angular2/core'.
8+
9+
declare function foo(...args: any[]);
10+
11+
@foo
12+
export class MyClass1 {
13+
constructor(private _elementRef: ng.ElementRef){}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"scenario": "Emit decorator metadata when commonJS and isolatedModules are on",
3+
"projectRoot": "tests/cases/projects/decoratorMetadata/emitDecoratorMetadataCommonJSIsolatedModuleNoResolve",
4+
"baselineCheck": true,
5+
"runTest": true,
6+
"resolvedInputFiles": [
7+
"lib.d.ts",
8+
"main.ts"
9+
],
10+
"emittedFiles": [
11+
"main.js"
12+
]
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6+
return c > 3 && r && Object.defineProperty(target, key, r), r;
7+
};
8+
var __metadata = (this && this.__metadata) || function (k, v) {
9+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10+
};
11+
var ng = require("angular2/core");
12+
var MyClass1 = (function () {
13+
function MyClass1(_elementRef) {
14+
this._elementRef = _elementRef;
15+
}
16+
MyClass1 = __decorate([
17+
foo,
18+
__metadata('design:paramtypes', [(typeof (_a = typeof ng !== 'undefined' && ng.ElementRef) === 'function' && _a) || Object])
19+
], MyClass1);
20+
return MyClass1;
21+
var _a;
22+
}());
23+
exports.MyClass1 = MyClass1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
main.ts(1,21): error TS2307: Cannot find module 'angular2/core'.
2+
3+
4+
==== main.ts (1 errors) ====
5+
import * as ng from "angular2/core";
6+
~~~~~~~~~~~~~~~
7+
!!! error TS2307: Cannot find module 'angular2/core'.
8+
9+
declare function foo(...args: any[]);
10+
11+
@foo
12+
export class MyClass1 {
13+
constructor(private _elementRef: ng.ElementRef){}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"scenario": "Emit decorator metadata when commonJS and isolatedModules are on",
3+
"projectRoot": "tests/cases/projects/decoratorMetadata/emitDecoratorMetadataSystemJS",
4+
"baselineCheck": true,
5+
"runTest": true,
6+
"resolvedInputFiles": [
7+
"lib.d.ts",
8+
"main.ts"
9+
],
10+
"emittedFiles": [
11+
"main.js"
12+
]
13+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5+
return c > 3 && r && Object.defineProperty(target, key, r), r;
6+
};
7+
var __metadata = (this && this.__metadata) || function (k, v) {
8+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9+
};
10+
define(["require", "exports", "angular2/core"], function (require, exports, ng) {
11+
"use strict";
12+
var MyClass1 = (function () {
13+
function MyClass1(_elementRef) {
14+
this._elementRef = _elementRef;
15+
}
16+
MyClass1 = __decorate([
17+
foo,
18+
__metadata('design:paramtypes', [(typeof (_a = typeof ng !== 'undefined' && ng.ElementRef) === 'function' && _a) || Object])
19+
], MyClass1);
20+
return MyClass1;
21+
var _a;
22+
}());
23+
exports.MyClass1 = MyClass1;
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
main.ts(1,21): error TS2307: Cannot find module 'angular2/core'.
2+
3+
4+
==== main.ts (1 errors) ====
5+
import * as ng from "angular2/core";
6+
~~~~~~~~~~~~~~~
7+
!!! error TS2307: Cannot find module 'angular2/core'.
8+
9+
declare function foo(...args: any[]);
10+
11+
@foo
12+
export class MyClass1 {
13+
constructor(private _elementRef: ng.ElementRef){}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"scenario": "Emit decorator metadata when commonJS and isolatedModules are on",
3+
"projectRoot": "tests/cases/projects/decoratorMetadata/emitDecoratorMetadataSystemJS",
4+
"baselineCheck": true,
5+
"runTest": true,
6+
"resolvedInputFiles": [
7+
"lib.d.ts",
8+
"main.ts"
9+
],
10+
"emittedFiles": [
11+
"main.js"
12+
]
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6+
return c > 3 && r && Object.defineProperty(target, key, r), r;
7+
};
8+
var __metadata = (this && this.__metadata) || function (k, v) {
9+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10+
};
11+
var ng = require("angular2/core");
12+
var MyClass1 = (function () {
13+
function MyClass1(_elementRef) {
14+
this._elementRef = _elementRef;
15+
}
16+
MyClass1 = __decorate([
17+
foo,
18+
__metadata('design:paramtypes', [(typeof (_a = typeof ng !== 'undefined' && ng.ElementRef) === 'function' && _a) || Object])
19+
], MyClass1);
20+
return MyClass1;
21+
var _a;
22+
}());
23+
exports.MyClass1 = MyClass1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
main.ts(1,21): error TS2307: Cannot find module 'angular2/core'.
2+
3+
4+
==== main.ts (1 errors) ====
5+
import * as ng from "angular2/core";
6+
~~~~~~~~~~~~~~~
7+
!!! error TS2307: Cannot find module 'angular2/core'.
8+
9+
declare function foo(...args: any[]);
10+
11+
@foo
12+
export class MyClass1 {
13+
constructor(private _elementRef: ng.ElementRef){}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"scenario": "Emit decorator metadata when commonJS and isolatedModules are on",
3+
"projectRoot": "tests/cases/projects/decoratorMetadata/emitDecoratorMetadataSystemJSIsolatedModule",
4+
"baselineCheck": true,
5+
"runTest": true,
6+
"resolvedInputFiles": [
7+
"lib.d.ts",
8+
"main.ts"
9+
],
10+
"emittedFiles": [
11+
"main.js"
12+
]
13+
}

0 commit comments

Comments
 (0)