Skip to content

Commit

Permalink
Use @glimmer/compiler-delegates
Browse files Browse the repository at this point in the history
Note: this commit relies on some unpublished changes in @glimmer/compiler-delegates.
tomdale committed Oct 30, 2017
1 parent 32fe7fc commit 4a3fc2b
Showing 7 changed files with 161 additions and 354 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@
},
"dependencies": {
"@glimmer/bundle-compiler": "^0.29.8",
"@glimmer/compiler-delegates": "^0.9.0-alpha.1",
"@glimmer/syntax": "^0.29.8",
"babel-core": "^7.0.0-alpha.19",
"babel-plugin-syntax-class-properties": "^7.0.0-alpha.19",
27 changes: 11 additions & 16 deletions src/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ConcatSource, RawSource } from 'webpack-sources';
import { BundleCompiler, CompilerDelegate, Specifier, specifierFor, SpecifierMap } from '@glimmer/bundle-compiler';
import { BundleCompiler, Specifier, specifierFor } from '@glimmer/bundle-compiler';
import { expect } from '@glimmer/util';
import { ConstantPool } from '@glimmer/program';
import { BundleCompilerDelegate } from '@glimmer/compiler-delegates';

import ComponentRegistry from './component-registry';
import { ConstantPool } from '@glimmer/program';
import { AST } from '@glimmer/syntax';

export interface Resolver {
resolveSync(context: {}, path: string, request: string): string | null;
@@ -14,13 +14,6 @@ export interface Specifiers {
[key: string]: Specifier;
}

export interface BundleCompilerDelegate extends CompilerDelegate {
bundleCompiler: BundleCompiler;
add(modulePath: string, templateSource: string, meta: Metadata): void;
addAST(modulePath: string, ast: AST.Program): void;
generateDataSegment(map: SpecifierMap, pool: ConstantPool, heapTable: number[]): string;
}

interface BundleOptions {
helpers?: Specifiers;
delegate: BundleCompilerDelegate;
@@ -54,15 +47,17 @@ export default class Bundle {
this.helpers = helpers || {};
this.delegate = delegate;

this.bundleCompiler = delegate.bundleCompiler = new BundleCompiler(delegate);
this.bundleCompiler = new BundleCompiler(delegate);
}

add(modulePath: string, templateSource: string, meta: Metadata) {
this.delegate.add(modulePath, templateSource, meta);
add(absoluteModulePath: string, templateSource: string, _meta: Metadata) {
let specifier = this.normalizeSpecifier(absoluteModulePath);
this.bundleCompiler.add(specifier, templateSource);
}

addAST(modulePath: string, ast: AST.Program) {
this.delegate.addAST(modulePath, ast);
protected normalizeSpecifier(absoluteModulePath: string) {
let normalizedPath = this.delegate.normalizePath(absoluteModulePath);
return specifierFor(normalizedPath, 'default');
}

compile() {
@@ -79,7 +74,7 @@ export default class Bundle {
entryHandle
};

let data = this.delegate.generateDataSegment(map, pool, heap.table);
let data = this.delegate.generateDataSegment(map, pool, heap.table, heap.handle, bundleCompiler.compiledBlocks);

return {
bytecode: new RawSource(heap.buffer as any),
15 changes: 6 additions & 9 deletions src/compiler-delegates/basic.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import { expect } from '@glimmer/util';
import { specifierFor, BundleCompiler, Specifier } from '@glimmer/bundle-compiler';
import Scope from '../scope';
import { SerializedTemplateBlock } from '@glimmer/wire-format';
import { BundleCompilerDelegate } from '../bundle';
import { BundleCompilerDelegate } from '@glimmer/compiler-delegates';
import { TemplateCompiler } from '@glimmer/compiler';
import { AST } from '@glimmer/syntax';

@@ -21,20 +21,17 @@ const CAPABILITIES = {
attributeHook: true
};

interface BasicMetadata {
scope: Scope;
}

export default class BasicCompilerDelegate implements BundleCompilerDelegate {
bundleCompiler: BundleCompiler;

protected scopes = new Map<Specifier, Scope>();

add(modulePath: string, templateSource: string, meta: BasicMetadata) {
let specifier = specifierFor(modulePath, 'default');
this.bundleCompiler.add(specifier, templateSource);
normalizePath(absoluteModulePath: string) {
return absoluteModulePath;
}

this.scopes.set(specifier, meta.scope);
specifierFor(modulePath: string) {
return specifierFor(modulePath, 'default');
}

addAST(modulePath: string, ast: AST.Program) {
Loading

0 comments on commit 4a3fc2b

Please sign in to comment.