Created
December 11, 2019 13:50
-
-
Save wtho/0db9f9f4d224ae85d65ad9e54293abdb to your computer and use it in GitHub Desktop.
Simple TS Decorator compilation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ts = require('typescript') | |
const toCompile = ` | |
import { SomeDecorator } from 'fictional-decorators'; | |
class Compilee { | |
constructor(@SomeDecorator() param) { } | |
} | |
` | |
const compiled = ts.transpileModule(toCompile, { | |
compilerOptions: { | |
baseUrl: './', | |
outputDir: './dist', | |
experimentalDecorators: true, | |
emitDecoratorMetadata: true | |
} | |
}) | |
console.log(compiled.outputText) | |
// "use strict"; | |
// var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | |
// var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | |
// if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | |
// 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; | |
// return c > 3 && r && Object.defineProperty(target, key, r), r; | |
// }; | |
// var __metadata = (this && this.__metadata) || function (k, v) { | |
// if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | |
// }; | |
// var __param = (this && this.__param) || function (paramIndex, decorator) { | |
// return function (target, key) { decorator(target, key, paramIndex); } | |
// }; | |
// Object.defineProperty(exports, "__esModule", { value: true }); | |
// var fictional_decorators_1 = require("fictional-decorators"); | |
// var Compilee = /** @class */ (function () { | |
// function Compilee(param) { | |
// } | |
// Compilee = __decorate([ | |
// __param(0, fictional_decorators_1.SomeDecorator()), | |
// __metadata("design:paramtypes", [Object]) | |
// ], Compilee); | |
// return Compilee; | |
// }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment