Write synthesized node's text property instead of getting text from source file

This fixes issue of not being able to emit qualified expression correctly
This commit is contained in:
Sheetal Nandi 2015-08-24 12:06:21 -07:00
parent 6c457f6c1d
commit 979e2bf7c4
9 changed files with 373 additions and 0 deletions

View File

@ -1552,6 +1552,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
else if (isNameOfNestedRedeclaration(node)) {
write(getGeneratedNameForNode(node));
}
else if (nodeIsSynthesized(node)) {
write(node.text);
}
else {
writeTextOfNode(currentSourceFile, node);
}

View File

@ -0,0 +1,51 @@
//// [tests/cases/compiler/decoratorMetadataWithImportDeclarationNameCollision3.ts] ////
//// [db.ts]
export class db {
public doSomething() {
}
}
//// [service.ts]
import db = require('./db');
function someDecorator(target) {
return target;
}
@someDecorator
class MyClass {
db: db.db;
constructor(db: db.db) { // collision with namespace of external module db
this.db = db;
this.db.doSomething();
}
}
export {MyClass};
//// [db.js]
var db = (function () {
function db() {
}
db.prototype.doSomething = function () {
};
return db;
})();
exports.db = db;
//// [service.js]
var db = require('./db');
function someDecorator(target) {
return target;
}
var MyClass = (function () {
function MyClass(db) {
this.db = db;
this.db.doSomething();
}
MyClass = __decorate([
someDecorator,
__metadata('design:paramtypes', [db.db])
], MyClass);
return MyClass;
})();
exports.MyClass = MyClass;

View File

@ -0,0 +1,53 @@
=== tests/cases/compiler/service.ts ===
import db = require('./db');
>db : Symbol(db, Decl(service.ts, 0, 0))
function someDecorator(target) {
>someDecorator : Symbol(someDecorator, Decl(service.ts, 0, 28))
>target : Symbol(target, Decl(service.ts, 1, 23))
return target;
>target : Symbol(target, Decl(service.ts, 1, 23))
}
@someDecorator
>someDecorator : Symbol(someDecorator, Decl(service.ts, 0, 28))
class MyClass {
>MyClass : Symbol(MyClass, Decl(service.ts, 3, 1))
db: db.db;
>db : Symbol(db, Decl(service.ts, 5, 15))
>db : Symbol(db, Decl(service.ts, 0, 0))
>db : Symbol(db.db, Decl(db.ts, 0, 0))
constructor(db: db.db) { // collision with namespace of external module db
>db : Symbol(db, Decl(service.ts, 8, 16))
>db : Symbol(db, Decl(service.ts, 0, 0))
>db : Symbol(db.db, Decl(db.ts, 0, 0))
this.db = db;
>this.db : Symbol(db, Decl(service.ts, 5, 15))
>this : Symbol(MyClass, Decl(service.ts, 3, 1))
>db : Symbol(db, Decl(service.ts, 5, 15))
>db : Symbol(db, Decl(service.ts, 8, 16))
this.db.doSomething();
>this.db.doSomething : Symbol(db.db.doSomething, Decl(db.ts, 0, 17))
>this.db : Symbol(db, Decl(service.ts, 5, 15))
>this : Symbol(MyClass, Decl(service.ts, 3, 1))
>db : Symbol(db, Decl(service.ts, 5, 15))
>doSomething : Symbol(db.db.doSomething, Decl(db.ts, 0, 17))
}
}
export {MyClass};
>MyClass : Symbol(MyClass, Decl(service.ts, 13, 8))
=== tests/cases/compiler/db.ts ===
export class db {
>db : Symbol(db, Decl(db.ts, 0, 0))
public doSomething() {
>doSomething : Symbol(doSomething, Decl(db.ts, 0, 17))
}
}

View File

@ -0,0 +1,55 @@
=== tests/cases/compiler/service.ts ===
import db = require('./db');
>db : typeof db
function someDecorator(target) {
>someDecorator : (target: any) => any
>target : any
return target;
>target : any
}
@someDecorator
>someDecorator : (target: any) => any
class MyClass {
>MyClass : MyClass
db: db.db;
>db : db.db
>db : any
>db : db.db
constructor(db: db.db) { // collision with namespace of external module db
>db : db.db
>db : any
>db : db.db
this.db = db;
>this.db = db : db.db
>this.db : db.db
>this : MyClass
>db : db.db
>db : db.db
this.db.doSomething();
>this.db.doSomething() : void
>this.db.doSomething : () => void
>this.db : db.db
>this : MyClass
>db : db.db
>doSomething : () => void
}
}
export {MyClass};
>MyClass : typeof MyClass
=== tests/cases/compiler/db.ts ===
export class db {
>db : db
public doSomething() {
>doSomething : () => void
}
}

View File

@ -0,0 +1,51 @@
//// [tests/cases/compiler/decoratorMetadataWithImportDeclarationNameCollision8.ts] ////
//// [db.ts]
export class db {
public doSomething() {
}
}
//// [service.ts]
import database = require('./db');
function someDecorator(target) {
return target;
}
@someDecorator
class MyClass {
db: database.db;
constructor(db: database.db) { // no collision
this.db = db;
this.db.doSomething();
}
}
export {MyClass};
//// [db.js]
var db = (function () {
function db() {
}
db.prototype.doSomething = function () {
};
return db;
})();
exports.db = db;
//// [service.js]
var database = require('./db');
function someDecorator(target) {
return target;
}
var MyClass = (function () {
function MyClass(db) {
this.db = db;
this.db.doSomething();
}
MyClass = __decorate([
someDecorator,
__metadata('design:paramtypes', [database.db])
], MyClass);
return MyClass;
})();
exports.MyClass = MyClass;

View File

@ -0,0 +1,53 @@
=== tests/cases/compiler/service.ts ===
import database = require('./db');
>database : Symbol(database, Decl(service.ts, 0, 0))
function someDecorator(target) {
>someDecorator : Symbol(someDecorator, Decl(service.ts, 0, 34))
>target : Symbol(target, Decl(service.ts, 1, 23))
return target;
>target : Symbol(target, Decl(service.ts, 1, 23))
}
@someDecorator
>someDecorator : Symbol(someDecorator, Decl(service.ts, 0, 34))
class MyClass {
>MyClass : Symbol(MyClass, Decl(service.ts, 3, 1))
db: database.db;
>db : Symbol(db, Decl(service.ts, 5, 15))
>database : Symbol(database, Decl(service.ts, 0, 0))
>db : Symbol(database.db, Decl(db.ts, 0, 0))
constructor(db: database.db) { // no collision
>db : Symbol(db, Decl(service.ts, 8, 16))
>database : Symbol(database, Decl(service.ts, 0, 0))
>db : Symbol(database.db, Decl(db.ts, 0, 0))
this.db = db;
>this.db : Symbol(db, Decl(service.ts, 5, 15))
>this : Symbol(MyClass, Decl(service.ts, 3, 1))
>db : Symbol(db, Decl(service.ts, 5, 15))
>db : Symbol(db, Decl(service.ts, 8, 16))
this.db.doSomething();
>this.db.doSomething : Symbol(database.db.doSomething, Decl(db.ts, 0, 17))
>this.db : Symbol(db, Decl(service.ts, 5, 15))
>this : Symbol(MyClass, Decl(service.ts, 3, 1))
>db : Symbol(db, Decl(service.ts, 5, 15))
>doSomething : Symbol(database.db.doSomething, Decl(db.ts, 0, 17))
}
}
export {MyClass};
>MyClass : Symbol(MyClass, Decl(service.ts, 13, 8))
=== tests/cases/compiler/db.ts ===
export class db {
>db : Symbol(db, Decl(db.ts, 0, 0))
public doSomething() {
>doSomething : Symbol(doSomething, Decl(db.ts, 0, 17))
}
}

View File

@ -0,0 +1,55 @@
=== tests/cases/compiler/service.ts ===
import database = require('./db');
>database : typeof database
function someDecorator(target) {
>someDecorator : (target: any) => any
>target : any
return target;
>target : any
}
@someDecorator
>someDecorator : (target: any) => any
class MyClass {
>MyClass : MyClass
db: database.db;
>db : database.db
>database : any
>db : database.db
constructor(db: database.db) { // no collision
>db : database.db
>database : any
>db : database.db
this.db = db;
>this.db = db : database.db
>this.db : database.db
>this : MyClass
>db : database.db
>db : database.db
this.db.doSomething();
>this.db.doSomething() : void
>this.db.doSomething : () => void
>this.db : database.db
>this : MyClass
>db : database.db
>doSomething : () => void
}
}
export {MyClass};
>MyClass : typeof MyClass
=== tests/cases/compiler/db.ts ===
export class db {
>db : db
public doSomething() {
>doSomething : () => void
}
}

View File

@ -0,0 +1,26 @@
// @noemithelpers: true
// @experimentaldecorators: true
// @emitdecoratormetadata: true
// @target: es5
// @module: commonjs
// @filename: db.ts
export class db {
public doSomething() {
}
}
// @filename: service.ts
import db = require('./db');
function someDecorator(target) {
return target;
}
@someDecorator
class MyClass {
db: db.db;
constructor(db: db.db) { // collision with namespace of external module db
this.db = db;
this.db.doSomething();
}
}
export {MyClass};

View File

@ -0,0 +1,26 @@
// @noemithelpers: true
// @experimentaldecorators: true
// @emitdecoratormetadata: true
// @target: es5
// @module: commonjs
// @filename: db.ts
export class db {
public doSomething() {
}
}
// @filename: service.ts
import database = require('./db');
function someDecorator(target) {
return target;
}
@someDecorator
class MyClass {
db: database.db;
constructor(db: database.db) { // no collision
this.db = db;
this.db.doSomething();
}
}
export {MyClass};