Skip to content

Commit

Permalink
[BUGFIX beta] Prevent AST plugins from being shared across compiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Jun 8, 2015
1 parent 9e3c165 commit 6e4cbeb
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
17 changes: 14 additions & 3 deletions packages/ember-template-compiler/lib/system/compile_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/

import Ember from "ember-metal/core";
import plugins from "ember-template-compiler/plugins";
import { assign } from "ember-metal/merge";
import defaultPlugins from "ember-template-compiler/plugins";

/**
@private
Expand All @@ -16,15 +17,25 @@ export default function(_options) {
disableComponentGeneration = false;
}

var options = _options || {};
let options;
// When calling `Ember.Handlebars.compile()` a second argument of `true`
// had a special meaning (long since lost), this just gaurds against
// `options` being true, and causing an error during compilation.
if (options === true) {
if (_options === true) {
options = {};
} else {
options = assign({}, _options);
}

options.disableComponentGeneration = disableComponentGeneration;

let plugins = {
ast: defaultPlugins.ast.slice()
};

if (options.plugins && options.plugins.ast) {
plugins.ast = plugins.ast.concat(options.plugins.ast);
}
options.plugins = plugins;

options.buildMeta = function buildMeta(program) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import defaultPlugins from 'ember-template-compiler/plugins';
import compileOptions from "ember-template-compiler/system/compile_options";


function comparePlugins(options) {
let results = compileOptions(options);
let expectedPlugins = defaultPlugins.ast.slice();

expectedPlugins = expectedPlugins.concat(options.plugins.ast.slice());

deepEqual(results.plugins.ast, expectedPlugins);
}

QUnit.module('ember-htmlbars: compile_options');

QUnit.test('repeated function calls should be able to have separate plugins', function() {
comparePlugins({
plugins: {
ast: ['foo', 'bar']
}
});

comparePlugins({
plugins: {
ast: ['baz', 'qux']
}
});
});

QUnit.test('options is not required', function() {
let results = compileOptions();

deepEqual(results.plugins.ast, defaultPlugins.ast.slice());
});

QUnit.test('options.plugins is not required', function() {
let results = compileOptions({});

deepEqual(results.plugins.ast, defaultPlugins.ast.slice());
});

QUnit.test('options.plugins.ast is not required', function() {
let results = compileOptions({
plugins: {}
});

deepEqual(results.plugins.ast, defaultPlugins.ast.slice());
});
6 changes: 5 additions & 1 deletion packages/loader/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ var define, requireModule, require, requirejs, Ember;
var mainContext = this;

(function() {
var isNode = typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';

if (!isNode) {
Ember = this.Ember = this.Ember || {};
}

Ember = this.Ember = this.Ember || {};
if (typeof Ember === 'undefined') { Ember = {}; };

if (typeof Ember.__loader === 'undefined') {
Expand Down

0 comments on commit 6e4cbeb

Please sign in to comment.