Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Glimmer Macros For Binary VM #14781

Merged
merged 3 commits into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 76 additions & 32 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,46 @@ function routeRecognizer() {
});
}

function buildPackage(name, options) {
options = options ? options : {};
var packageJson = require(name + '/package');
var packageDir = path.dirname(require.resolve(name + '/package'));

if (options.entry && !options.srcDir) {
throw new Error('If resolving from a non-package.json entry point, you must supply the srcDirectory.');
}

var entryModule = packageJson['module'] || packageJson['js:next'] || packageJson['main'].replace(/dist\//, 'dist/es6/');
var funnelDir = path.join(packageDir, options.entry ? options.srcDir : path.dirname(entryModule));
var sourceEntry = options.entry ? options.entry : path.basename(entryModule);

var es6 = new Funnel(funnelDir, {
include: ['**/*.js' ]
});
var moduleId = options.moduleId ? options.moduleId : name;
var destination = options.dest ? options.dest + '.js': moduleId + '.js';
var external = options.external ? options.external : [];
var plugins = options.plugins ? options.plugins : [];
var rolledUp = new Rollup(es6, {
rollup: {
external: external,
entry: sourceEntry,
dest: destination,
plugins: plugins,
format: 'es',
moduleId: moduleId,
exports: 'named'
},
annotation: destination
});

var transpileES6 = require('emberjs-build/lib/utils/transpile-es6');

return transpileES6(rolledUp, name, {
stripRuntimeChecks: true
});
}

function router() {
return new Rollup(path.resolve(path.dirname(require.resolve('router_js')), '../lib'), {
rollup: {
Expand Down Expand Up @@ -197,27 +237,6 @@ function babelConfigFor(environment) {
};
}

var glimmerEngine = require('glimmer-engine/ember-cli-build')({
shouldExternalizeHelpers: true,
stripRuntimeChecks: true
});

function glimmerPackage(name) {
return replace(new Funnel(glimmerEngine, {
include: [
'named-amd/' + name + '.js',
'named-amd/' + name + '/**/*.js'
]
}), {
files: ['**/*.js'],
pattern: {
match: /\/\/#\s+sourceMappingURL.*/g,
replacement: ''
},
annotation: 'strip sourceMappingURL'
});
}

function getVersion() {
var projectPath = process.cwd();
var info = getGitInfo(projectPath);
Expand Down Expand Up @@ -254,6 +273,21 @@ function qunit() {
});
}

function handlebarsFix() {
var HANDLEBARS_UTIL = /\/utils.js$/;
return {
load: function(id) {
if (HANDLEBARS_UTIL.test(id)) {
var code = fs.readFileSync(id, 'utf8');
return {
code: code.replace(/export var isFunction/, 'export { isFunction }'),
map: { mappings: null }
};
}
}
}
}

module.exports = function() {
var features = getFeatures();
var version = getVersion();
Expand All @@ -268,16 +302,26 @@ module.exports = function() {
'route-recognizer': routeRecognizer(),
'simple-html-tokenizer': htmlbarsPackage('simple-html-tokenizer', { libPath: 'node_modules/glimmer-engine/dist/es6' }),

'glimmer': glimmerPackage('glimmer'),
'glimmer-compiler': glimmerPackage('glimmer-compiler'),
'glimmer-reference': glimmerPackage('glimmer-reference'),
'glimmer-runtime': glimmerPackage('glimmer-runtime'),
'glimmer-node': glimmerPackage('glimmer-node'),
'glimmer-syntax': glimmerPackage('glimmer-syntax'),
'glimmer-test-helpers': glimmerPackage('glimmer-test-helpers'),
'glimmer-util': glimmerPackage('glimmer-util'),
'glimmer-wire-format': glimmerPackage('glimmer-wire-format'),
'handlebars': glimmerPackage('handlebars') // inlined parser
'@glimmer/compiler': buildPackage('@glimmer/compiler', {
external: ['@glimmer/syntax', '@glimmer/wire-format', '@glimmer/util']
}),
'@glimmer/reference': buildPackage('@glimmer/reference', { external: ['@glimmer/util'] }),
'@glimmer/runtime': buildPackage('@glimmer/runtime', {
external: ['@glimmer/util',
'@glimmer/reference',
'@glimmer/wire-format',
'@glimmer/syntax']
}),
'@glimmer/node': buildPackage('@glimmer/node', { external: ['@glimmer/runtime'] }),
'@glimmer/syntax': buildPackage('@glimmer/syntax', { external: ['handlebars', 'simple-html-tokenizer'] }),
'@glimmer/test-helpers': buildPackage('@glimmer/test-helpers'),
'@glimmer/util': buildPackage('@glimmer/util', { external: [] }),
'@glimmer/wire-format': buildPackage('@glimmer/wire-format', { external: ['@glimmer/util'] }),
'handlebars': buildPackage('handlebars', {
srcDir: 'lib',
entry: 'handlebars/compiler/base.js',
plugins: [handlebarsFix()]
}) // inlined parser
};

// Replace _getBowerTree with one from npm
Expand Down Expand Up @@ -349,7 +393,7 @@ module.exports = function() {
development: getFeatures('development'),
production: getFeatures('production')
},
glimmer: require('glimmer-engine'),
glimmer: require('@glimmer/compiler'),
packages: getPackages(features),
vendoredPackages: vendorPackages,
version: version
Expand Down
23 changes: 11 additions & 12 deletions lib/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ module.exports = function(features) {
templateCompilerVendor: [
'simple-html-tokenizer',
'backburner',
'glimmer-wire-format',
'glimmer-syntax',
'glimmer-util',
'glimmer-compiler',
'glimmer-reference',
'glimmer-runtime',
'@glimmer/wire-format',
'@glimmer/syntax',
'@glimmer/util',
'@glimmer/compiler',
'@glimmer/reference',
'@glimmer/runtime',
'handlebars'
]
},
Expand All @@ -37,12 +37,11 @@ module.exports = function(features) {
requirements: ['container', 'ember-metal', 'ember-routing' ],
hasTemplates: true,
vendorRequirements: [
'glimmer',
'glimmer-runtime',
'glimmer-reference',
'glimmer-util',
'glimmer-wire-format',
'glimmer-node'
'@glimmer/runtime',
'@glimmer/reference',
'@glimmer/util',
'@glimmer/wire-format',
'@glimmer/node'
],
testingVendorRequirements: []
}
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"test:testem": "testem -f testem.dist.json"
},
"dependencies": {
"@glimmer/compiler": "^0.21.1",
"@glimmer/node": "^0.21.1",
"@glimmer/reference": "^0.21.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these all be the same version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I don't believe so. The way lerna publish works is that it looks if packages were effected in between the HEAD and the last tag if its not effected it will not publish a new version.

"@glimmer/runtime": "^0.21.1",
"@glimmer/util": "^0.21.0",
"broccoli-stew": "^1.2.0",
"ember-cli-get-component-path-option": "^1.0.0",
"ember-cli-normalize-entity-name": "^1.0.0",
Expand All @@ -35,12 +40,14 @@
"ember-cli-test-info": "^1.0.0",
"ember-cli-valid-component-name": "^1.0.0",
"ember-cli-version-checker": "^1.1.7",
"handlebars": "~3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does ember have a handlebars dep? Seems like this should be in Glimmer and handled upon its publishing, or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krisselden might want to chime in here. I don't remember why we did this.

"jquery": "^3.1.1",
"resolve": "^1.1.7",
"rsvp": "^3.3.3",
"simple-dom": "^0.3.0"
},
"devDependencies": {
"@glimmer/test-helpers": "^0.21.1",
"aws-sdk": "~2.2.43",
"babel-plugin-feature-flags": "^0.2.3",
"babel-plugin-filter-imports": "~0.2.0",
Expand All @@ -64,7 +71,7 @@
"git-repo-info": "^1.1.4",
"git-repo-version": "^0.3.1",
"github": "^0.2.3",
"glimmer-engine": "^0.19.4",
"glimmer-engine": "^0.20.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need glimmer-engine?

"glob": "^5.0.13",
"html-differ": "^1.3.4",
"mocha": "^2.4.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-glimmer/lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
deprecate
} from 'ember-metal';
import { UPDATE, RootReference } from './utils/references';
import { DirtyableTag } from 'glimmer-reference';
import { readDOMAttr } from 'glimmer-runtime';
import { DirtyableTag } from '@glimmer/reference';
import { readDOMAttr } from '@glimmer/runtime';

export const DIRTY_TAG = symbol('DIRTY_TAG');
export const ARGS = symbol('ARGS');
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-glimmer/lib/dom.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { DOMChanges, DOMTreeConstruction } from 'glimmer-runtime';
export { NodeDOMTreeConstruction } from 'glimmer-node';
export { DOMChanges, DOMTreeConstruction } from '@glimmer/runtime';
export { NodeDOMTreeConstruction } from '@glimmer/node';
116 changes: 8 additions & 108 deletions packages/ember-glimmer/lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import {
isSafeString,
compileLayout,
getDynamicVar
} from 'glimmer-runtime';
} from '@glimmer/runtime';
import {
CurlyComponentSyntax,
CurlyComponentDefinition
} from './syntax/curly-component';
import { findSyntaxBuilder } from './syntax';
import { DynamicComponentSyntax } from './syntax/dynamic-component';
import {
populateMacros
} from './syntax';
import createIterable from './utils/iterable';
import {
ConditionalReference,
Expand All @@ -31,12 +31,9 @@ import {
inlineIf,
inlineUnless
} from './helpers/if-unless';
import { wrapComponentClassAttribute } from './utils/bindings';

import { default as action } from './helpers/action';
import { default as componentHelper } from './helpers/component';
import { default as concat } from './helpers/concat';
import { default as debuggerHelper } from './helpers/debugger';
import { default as get } from './helpers/get';
import { default as hash } from './helpers/hash';
import { default as loc } from './helpers/loc';
Expand All @@ -54,10 +51,6 @@ import { default as htmlSafeHelper } from './helpers/-html-safe';
import installPlatformSpecificProtocolForURL from './protocol-for-url';
import { FACTORY_FOR } from 'container';

const builtInComponents = {
textarea: '-text-area'
};

import { default as ActionModifierManager } from './modifiers/action';

export default class Environment extends GlimmerEnvironment {
Expand Down Expand Up @@ -117,7 +110,6 @@ export default class Environment extends GlimmerEnvironment {
action,
component: componentHelper,
concat,
debugger: debuggerHelper,
get,
hash,
loc,
Expand All @@ -138,102 +130,10 @@ export default class Environment extends GlimmerEnvironment {
runInDebug(() => this.debugStack = new DebugStack());
}

// Hello future traveler, welcome to the world of syntax refinement.
// The method below is called by Glimmer's runtime compiler to allow
// us to take generic statement syntax and refine it to more meaniful
// syntax for Ember's use case. This on the fly switch-a-roo sounds fine
// and dandy, however Ember has precedence on statement refinement that you
// need to be aware of. The presendence for language constructs is as follows:
//
// ------------------------
// Native & Built-in Syntax
// ------------------------
// User-land components
// ------------------------
// User-land helpers
// ------------------------
//
// The one caveat here is that Ember also allows for dashed references that are
// not a component or helper:
//
// export default Component.extend({
// 'foo-bar': 'LAME'
// });
//
// {{foo-bar}}
//
// The heuristic for the above situation is a dashed "key" in inline form
// that does not resolve to a defintion. In this case refine statement simply
// isn't going to return any syntax and the Glimmer engine knows how to handle
// this case.

refineStatement(statement, symbolTable) {
// 1. resolve any native syntax – if, unless, with, each, and partial
let nativeSyntax = super.refineStatement(statement, symbolTable);

if (nativeSyntax) {
return nativeSyntax;
}

let {
appendType,
isSimple,
isInline,
isBlock,
isModifier,
key,
path,
args
} = statement;

assert(`You attempted to overwrite the built-in helper "${key}" which is not allowed. Please rename the helper.`, !(this.builtInHelpers[key] && this.owner.hasRegistration(`helper:${key}`)));

if (isSimple && (isInline || isBlock) && appendType !== 'get') {
// 2. built-in syntax

let RefinedSyntax = findSyntaxBuilder(key);
if (RefinedSyntax) {
return RefinedSyntax.create(this, args, symbolTable);
}

let internalKey = builtInComponents[key];
let definition = null;

if (internalKey) {
definition = this.getComponentDefinition([internalKey], symbolTable);
} else if (key.indexOf('-') >= 0) {
definition = this.getComponentDefinition(path, symbolTable);
}

if (definition) {
wrapComponentClassAttribute(args);

return new CurlyComponentSyntax(args, definition, symbolTable);
}

assert(`A component or helper named "${key}" could not be found`, !isBlock || this.hasHelper(path, symbolTable));
}

if (isInline && !isSimple && appendType !== 'helper') {
return statement.original.deopt();
}

if (!isSimple && path) {
return DynamicComponentSyntax.fromPath(this, path, args, symbolTable);
}

assert(`Helpers may not be used in the block form, for example {{#${key}}}{{/${key}}}. Please use a component, or alternatively use the helper in combination with a built-in Ember helper, for example {{#if (${key})}}{{/if}}.`, !isBlock || !this.hasHelper(path, symbolTable));

assert(`Helpers may not be used in the element form.`, (() => {
if (nativeSyntax) { return true; }
if (!key) { return true; }

if (isModifier && !this.hasModifier(path, symbolTable) && this.hasHelper(path, symbolTable)) {
return false;
}

return true;
})());
macros() {
let macros = super.macros();
populateMacros(macros.blocks, macros.inlines);
return macros;
}

hasComponentDefinition() {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { symbol } from 'ember-utils';
import { FrameworkObject } from 'ember-runtime';
import { DirtyableTag } from 'glimmer-reference';
import { DirtyableTag } from '@glimmer/reference';

export const RECOMPUTE_TAG = symbol('RECOMPUTE_TAG');

Expand Down
Loading