Skip to content

Commit

Permalink
wip update glimmer
Browse files Browse the repository at this point in the history
  • Loading branch information
krisselden authored and Chris Garrett committed Jan 7, 2020
1 parent ceabba8 commit ade8188
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 208 deletions.
1 change: 1 addition & 0 deletions broccoli/glimmer-bundle-compiler-stub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Constants as DebugConstants } from '@glimmer/program';
1 change: 1 addition & 0 deletions broccoli/glimmer-compiler-stub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function precompile() {}
15 changes: 13 additions & 2 deletions broccoli/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ function rollupGlimmerPackage(pkg) {
file: name + '.js',
format: 'es',
},
plugins: [{
resolveId(id) {
if (pkg.name === '@glimmer/opcode-compiler') {
if (id === '@glimmer/compiler') {
return require.resolve('./glimmer-compiler-stub');
} else if (id === '@glimmer/bundle-compiler') {
return require.resolve('./glimmer-bundle-compiler-stub');
}
}
}
}]
},
annotation: name,
});
Expand All @@ -254,7 +265,7 @@ function glimmerTrees(entries) {
}
seen.add(name);

if (!name.startsWith('@glimmer/')) {
if (!name.startsWith('@glimmer/') && !name.startsWith("@simple-dom/")) {
continue;
}

Expand Down Expand Up @@ -284,7 +295,7 @@ module.exports.glimmerCompilerES = () => {
};

module.exports.glimmerES = function glimmerES(environment) {
let glimmerEntries = ['@glimmer/node', '@glimmer/opcode-compiler', '@glimmer/runtime'];
let glimmerEntries = ['@glimmer/node', '@simple-dom/document', '@glimmer/opcode-compiler', '@glimmer/runtime'];

if (environment === 'development') {
let hasGlimmerDebug = true;
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@
},
"devDependencies": {
"@babel/preset-env": "^7.7.7",
"@glimmer/compiler": "0.38.5-alpha.3",
"@glimmer/compiler": "0.44.0",
"@glimmer/env": "^0.1.7",
"@glimmer/interfaces": "0.38.5-alpha.3",
"@glimmer/node": "0.38.5-alpha.3",
"@glimmer/opcode-compiler": "0.38.5-alpha.3",
"@glimmer/program": "0.38.5-alpha.3",
"@glimmer/reference": "0.38.5-alpha.3",
"@glimmer/runtime": "0.38.5-alpha.3",
"@glimmer/interfaces": "0.44.0",
"@glimmer/node": "0.44.0",
"@glimmer/opcode-compiler": "0.44.0",
"@glimmer/program": "0.44.0",
"@glimmer/reference": "0.44.0",
"@glimmer/runtime": "0.44.0",
"@simple-dom/document": "^1.4.0",
"@types/qunit": "^2.5.4",
"@types/rsvp": "^4.0.3",
"@typescript-eslint/parser": "^2.15.0",
Expand All @@ -98,7 +99,7 @@
"broccoli-rollup": "^2.1.1",
"broccoli-source": "^3.0.0",
"broccoli-string-replace": "^0.1.2",
"broccoli-typescript-compiler": "^4.1.0",
"broccoli-typescript-compiler": "^4.2.0",
"broccoli-uglify-sourcemap": "^3.1.1",
"common-tags": "^1.8.0",
"core-js": "^2.6.5",
Expand Down
94 changes: 16 additions & 78 deletions packages/@ember/-internals/glimmer/lib/syntax.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,14 @@
import { OwnedTemplateMeta } from '@ember/-internals/views';
import { assert } from '@ember/debug';
import { CompilableBlock } from '@glimmer/interfaces';
import { Macros, OpcodeBuilder } from '@glimmer/opcode-compiler';
import { Option } from '@glimmer/util';
import { Core } from '@glimmer/wire-format';
import CompileTimeLookup from './compile-time-lookup';
import { blockLetMacro } from './syntax/let';
import { mountMacro } from './syntax/mount';
import { outletMacro } from './syntax/outlet';
import { hashToArgs } from './syntax/utils';

function refineInlineSyntax(
name: string,
params: Option<Core.Params>,
hash: Option<Core.Hash>,
builder: OpcodeBuilder<OwnedTemplateMeta>
): boolean {
assert(
`You attempted to overwrite the built-in helper "${name}" which is not allowed. Please rename the helper.`,
!(
(builder.compiler['resolver'] as CompileTimeLookup)['resolver']['builtInHelpers'][name] &&
builder.referrer.owner.hasRegistration(`helper:${name}`)
)
);

let handle = builder.compiler['resolver'].lookupComponentDefinition(name, builder.referrer);

if (handle !== null) {
builder.component.static(handle, [params === null ? [] : params, hashToArgs(hash), null, null]);
return true;
}

return false;
}

function refineBlockSyntax(
name: string,
params: Core.Params,
hash: Core.Hash,
template: Option<CompilableBlock>,
inverse: Option<CompilableBlock>,
builder: OpcodeBuilder<OwnedTemplateMeta>
) {
let handle = builder.compiler['resolver'].lookupComponentDefinition(name, builder.referrer);

if (handle !== null) {
builder.component.static(handle, [params, hashToArgs(hash), template, inverse]);
return true;
}

assert(
`A component or helper named "${name}" could not be found`,
builder.referrer.owner.hasRegistration(`helper:${name}`)
);

assert(
`Helpers may not be used in the block form, for example {{#${name}}}{{/${name}}}. Please use a component, or alternatively use the helper in combination with a built-in Ember helper, for example {{#if (${name})}}{{/if}}.`,
!(() => {
const resolver = (builder.compiler['resolver'] as CompileTimeLookup)['resolver'];
const { owner, moduleName } = builder.referrer;
if (name === 'component' || resolver['builtInHelpers'][name]) {
return true;
}
let options = { source: `template:${moduleName}` };
return (
owner.hasRegistration(`helper:${name}`, options) || owner.hasRegistration(`helper:${name}`)
);
})()
);

return false;
}
// import { OwnedTemplateMeta } from '@ember/-internals/views';
// import { assert } from '@ember/debug';
import { Macros, } from '@glimmer/interfaces';
// import { staticComponent } from '@glimmer/opcode-compiler';
// import { Option } from '@glimmer/util';
// import CompileTimeLookup from './compile-time-lookup';
// import { blockLetMacro } from './syntax/let';
// import { mountMacro } from './syntax/mount';
// import { outletMacro } from './syntax/outlet';
// import { hashToArgs } from './syntax/utils';
// import { wrapComponentClassAttribute } from './utils/bindings';

export const experimentalMacros: any[] = [];

Expand All @@ -83,13 +21,13 @@ export function registerMacros(macro: any) {

export function populateMacros(macros: Macros) {
let { inlines, blocks } = macros;
inlines.add('outlet', outletMacro);
inlines.add('mount', mountMacro);
// inlines.add('outlet', outletMacro);
// inlines.add('mount', mountMacro);

inlines.addMissing(refineInlineSyntax);
// inlines.addMissing(refineInlineSyntax);

blocks.add('let', blockLetMacro);
blocks.addMissing(refineBlockSyntax);
// blocks.add('let', blockLetMacro);
// blocks.addMissing(refineBlockSyntax);

for (let i = 0; i < experimentalMacros.length; i++) {
let macro = experimentalMacros[i];
Expand Down
16 changes: 7 additions & 9 deletions packages/@ember/-internals/glimmer/lib/template.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { privatize as P } from '@ember/-internals/container';
import { Owner } from '@ember/-internals/owner';
import { OwnedTemplateMeta, StaticTemplateMeta } from '@ember/-internals/views';
import { Template } from '@glimmer/interfaces';
import { LazyCompiler, templateFactory } from '@glimmer/opcode-compiler';
import { SerializedTemplateWithLazyBlock } from '@glimmer/wire-format';
import { SerializedTemplateWithLazyBlock, Template } from '@glimmer/interfaces';
import { templateFactory } from '@glimmer/opcode-compiler';

export type StaticTemplate = SerializedTemplateWithLazyBlock<StaticTemplateMeta>;
export type OwnedTemplate = Template<OwnedTemplateMeta>;
Expand All @@ -25,19 +23,19 @@ export let counters = {
cacheMiss: 0,
};

const TEMPLATE_COMPILER_MAIN = P`template-compiler:main`;

export default function template(json: StaticTemplate): Factory {
let glimmerFactory = templateFactory(json);
let cache = new WeakMap<Owner, OwnedTemplate>();

const meta = glimmerFactory.meta as StaticTemplateMeta;

let factory = ((owner: Owner) => {
let result = cache.get(owner);

if (result === undefined) {
counters.cacheMiss++;
let compiler = owner.lookup<LazyCompiler<StaticTemplateMeta>>(TEMPLATE_COMPILER_MAIN)!;
result = glimmerFactory.create(compiler, { owner });
// let compiler = owner.lookup<LazyCompiler<StaticTemplateMeta>>(TEMPLATE_COMPILER_MAIN)!;
result = glimmerFactory.create(Object.assign({ owner }, meta));
cache.set(owner, result);
} else {
counters.cacheHit++;
Expand All @@ -47,7 +45,7 @@ export default function template(json: StaticTemplate): Factory {
}) as Factory;

factory.__id = glimmerFactory.id;
factory.__meta = glimmerFactory.meta;
factory.__meta = meta;

return factory;
}
Expand Down
Loading

0 comments on commit ade8188

Please sign in to comment.