@travetto/compiler
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -7,3 +7,3 @@ { | ||
"dependencies": { | ||
"@travetto/base": "^0.1.1", | ||
"@travetto/base": "^0.1.2", | ||
"@types/source-map-support": "^0.4.1", | ||
@@ -32,3 +32,3 @@ "source-map-support": "^0.5.6", | ||
"scripts": {}, | ||
"version": "0.1.1" | ||
"version": "0.1.2" | ||
} |
import * as ts from 'typescript'; | ||
import { dirname, sep } from 'path'; | ||
import { AppInfo } from '@travetto/base'; | ||
import { AppInfo, Env } from '@travetto/base'; | ||
export type Import = { path: string, ident: ts.Identifier }; | ||
export type DecList = ts.NodeArray<ts.Decorator>; | ||
export interface State { | ||
export interface TransformerState { | ||
newImports: Import[]; | ||
@@ -17,3 +17,3 @@ path: string; | ||
static generateUniqueId(name: string, state: State) { | ||
static generateUniqueId(name: string, state: TransformerState) { | ||
const val = (state.ids.get(name) || 0) + 1; | ||
@@ -34,3 +34,3 @@ state.ids.set(name, val); | ||
static findAnyDecorator(node: ts.Node, patterns: { [key: string]: Set<string> }, state: State): ts.Decorator | undefined { | ||
static findAnyDecorator(node: ts.Node, patterns: { [key: string]: Set<string> }, state: TransformerState): ts.Decorator | undefined { | ||
for (const dec of (node.decorators || []) as any as DecList) { | ||
@@ -43,2 +43,3 @@ const ident = this.getDecoratorIdent(dec); | ||
const { path } = state.imports.get(ident.escapedText! as string)!; | ||
console.log(path, ident.escapedText!); | ||
const packages = patterns[ident.escapedText as string]; | ||
@@ -142,3 +143,3 @@ if (path.includes('@travetto') || (!path.includes('node_modules') && AppInfo.PACKAGE === '@travetto')) { | ||
static importingVisitor<T extends State>( | ||
static importingVisitor<T extends TransformerState>( | ||
init: (file: ts.SourceFile, context?: ts.TransformationContext) => Partial<T>, | ||
@@ -160,5 +161,10 @@ visitor: <Z extends ts.Node>(context: ts.TransformationContext, node: Z, state: T) => Z | ||
if (ts.isImportDeclaration(stmt) && ts.isStringLiteral(stmt.moduleSpecifier)) { | ||
const path = require.resolve(stmt.moduleSpecifier.text | ||
let path = require.resolve(stmt.moduleSpecifier.text | ||
.replace(/^\.\./, dirname(dirname(state.path))) | ||
.replace(/^\.\//, `${dirname(state.path)}/`)); | ||
if (Env.frameworkDev && path.includes('@travetto')) { | ||
path = `${Env.cwd}/node_modules/@travetto/${path.split('@travetto/').pop()}`; | ||
} | ||
if (stmt.importClause) { | ||
@@ -195,3 +201,3 @@ if (stmt.importClause.namedBindings) { | ||
static importIfExternal<T extends State>(typeNode: ts.TypeNode, state: State) { | ||
static importIfExternal<T extends TransformerState>(typeNode: ts.TypeNode, state: TransformerState) { | ||
// let { path, name: declName, ident: decl } = this.getTypeInfoForNode(node); | ||
@@ -198,0 +204,0 @@ |
@@ -14,3 +14,3 @@ import { CustomTransformers } from 'typescript'; | ||
for (const trns of ScanApp.requireFiles('.ts', x => /transformer[.].*[.]ts$/.test(x))) { | ||
for (const trns of ScanApp.requireFiles('.ts', x => /transformer[.].*?[.]ts$/.test(x))) { | ||
for (const key of Object.keys(trns)) { | ||
@@ -27,3 +27,5 @@ const item = trns[key]; | ||
for (const key of Object.keys(transformers)) { | ||
transformers[key] = (transformers[key] as any[]).sort((a, b) => a.priority - b.priority).map(x => x.transformer); | ||
transformers[key] = (transformers[key] as any[]) | ||
.sort((a, b) => a.priority - b.priority) | ||
.map(x => x.transformer); | ||
} | ||
@@ -30,0 +32,0 @@ this.transformers = transformers; |
@@ -1,19 +0,22 @@ | ||
import { initStackHandler } from '@travetto/base/src/stacktrace'; | ||
import { Suite, Test, BeforeAll } from '@travetto/test'; | ||
import { Stacktrace } from '@travetto/base/src/stacktrace'; | ||
initStackHandler(); | ||
@Suite() | ||
class StackTest { | ||
function test() { | ||
setTimeout(function inner1() { | ||
setTimeout(function inner2() { | ||
setTimeout(function inner3() { | ||
throw new Error('Uh ohs'); | ||
@BeforeAll() | ||
beforeAll() { | ||
Stacktrace.initHandler(); | ||
} | ||
@Test() | ||
async try() { | ||
setTimeout(function inner1() { | ||
setTimeout(function inner2() { | ||
setTimeout(function inner3() { | ||
throw new Error('Uh ohs'); | ||
}, 1); | ||
}, 1); | ||
}, 1); | ||
}, 1); | ||
} | ||
try { | ||
test(); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
} |
@@ -0,5 +1,12 @@ | ||
import { Suite, Test } from '@travetto/test'; | ||
import * as compiler from '../src/compiler'; | ||
setInterval(() => { | ||
console.log(compiler.Compiler.cwd); | ||
}, 2000); | ||
@Suite() | ||
class WatchTest { | ||
@Test() | ||
async testWatch() { | ||
setInterval(() => { | ||
console.log(compiler.Compiler.cwd); | ||
}, 2000); | ||
} | ||
} |
29820
757
16
Updated@travetto/base@^0.1.2