From fee313a8844bec4af4ccd8953966713ac68dd1ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mu=C3=B1oz?= Date: Wed, 26 Aug 2015 15:30:10 -0400 Subject: [PATCH] Remove most of defeatureify in favor of babel-plugin-filter-imports --- Brocfile.js | 24 ++++++++++------ features.json | 27 +----------------- package.json | 1 + .../node-managers/component-node-manager.js | 13 ++++----- packages/ember-metal/lib/core.js | 28 +++++++------------ packages/ember-metal/lib/mixin.js | 5 +--- 6 files changed, 34 insertions(+), 64 deletions(-) diff --git a/Brocfile.js b/Brocfile.js index af614b6f15b..31df8b76493 100644 --- a/Brocfile.js +++ b/Brocfile.js @@ -11,6 +11,7 @@ var EmberBuild = require('emberjs-build'); var packages = require('./lib/packages'); var applyFeatureFlags = require('babel-plugin-feature-flags'); +var filterImports = require('babel-plugin-filter-imports'); var vendoredPackage = require('emberjs-build/lib/vendored-package'); var htmlbarsPackage = require('emberjs-build/lib/htmlbars-package'); @@ -20,18 +21,25 @@ var featuresJson = fs.readFileSync('./features.json', { encoding: 'utf8' }); function babelConfigFor(environment) { var isDevelopment = (environment === 'development'); + var isProduction = (environment === 'production'); var features = JSON.parse(featuresJson).features; features["mandatory-setter"] = isDevelopment; - return { - plugins: [ - applyFeatureFlags({ - import: { module: 'ember-metal/features' }, - features: features - }) - ] - }; + var plugins = []; + + plugins.push(applyFeatureFlags({ + import: { module: 'ember-metal/features' }, + features: features + })); + + if (isProduction) { + plugins.push(filterImports({ + 'ember-metal/debug': ['assert','debug','deprecate','runInDebug','warn'] + })); + } + + return { plugins: plugins }; } var emberBuild = new EmberBuild({ diff --git a/features.json b/features.json index d5c44a43047..9ae3d0dd808 100644 --- a/features.json +++ b/features.json @@ -11,32 +11,7 @@ "ember-routing-routable-components": null }, "debugStatements": [ - "Ember.warn", - "Ember.default.warn", - "Ember.assert", - "Ember.default.assert", - "Ember.deprecate", - "Ember.default.deprecate", - "Ember.debug", - "Ember.default.debug", "Ember.Logger.info", - "Ember.default.Logger.info", - "Ember.runInDebug", - "Ember.default.runInDebug", - "_emberMetalCore.default.deprecate", - "_emberMetalCore.default.warn", - "_emberMetalCore.default.assert", - "_emberMetalCore.default.debug", - "_emberMetalCore.default.runInDebug", - "_emberMetal.default.deprecate", - "_emberMetal.default.warn", - "_emberMetal.default.assert", - "_emberMetal.default.debug", - "_emberMetal.default.runInDebug", - "_emberMetalDebug.deprecate", - "_emberMetalDebug.warn", - "_emberMetalDebug.assert", - "_emberMetalDebug.debug", - "_emberMetalDebug.runInDebug" + "Ember.default.Logger.info" ] } diff --git a/package.json b/package.json index e422a9859d3..07930ec18cf 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "devDependencies": { "aws-sdk": "~2.1.5", "babel-plugin-feature-flags": "~0.2.0", + "babel-plugin-filter-imports": "~0.2.0", "bower": "~1.3.2", "chalk": "^0.5.1", "ember-cli": "^0.2.7", diff --git a/packages/ember-htmlbars/lib/node-managers/component-node-manager.js b/packages/ember-htmlbars/lib/node-managers/component-node-manager.js index bb100eb300a..71b1c9db068 100644 --- a/packages/ember-htmlbars/lib/node-managers/component-node-manager.js +++ b/packages/ember-htmlbars/lib/node-managers/component-node-manager.js @@ -76,14 +76,11 @@ ComponentNodeManager.create = function(renderNode, env, options) { // now that we have the component instance. layout = get(component, 'layout') || layout; - // TODO: Remove this hack when defeatureify is removed. - let _assert = assert; - runInDebug(() => { if (isAngleBracket) { - _assert(`You cannot invoke the '${tagName}' component with angle brackets, because it's a subclass of Component. Please upgrade to GlimmerComponent. Alternatively, you can invoke as '{{${tagName}}}'.`, component.isGlimmerComponent); + assert(`You cannot invoke the '${tagName}' component with angle brackets, because it's a subclass of Component. Please upgrade to GlimmerComponent. Alternatively, you can invoke as '{{${tagName}}}'.`, component.isGlimmerComponent); } else { - _assert(`You cannot invoke the '${tagName}' component with curly braces, because it's a subclass of GlimmerComponent. Please invoke it as '<${tagName}>' instead.`, !component.isGlimmerComponent); + assert(`You cannot invoke the '${tagName}' component with curly braces, because it's a subclass of GlimmerComponent. Please invoke it as '<${tagName}>' instead.`, !component.isGlimmerComponent); } if (!layout) { return; } @@ -92,14 +89,14 @@ ComponentNodeManager.create = function(renderNode, env, options) { if (isAngleBracket && fragmentReason) { switch (fragmentReason.name) { case 'missing-wrapper': - _assert(`The <${tagName}> template must have a single top-level element because it is a GlimmerComponent.`); + assert(`The <${tagName}> template must have a single top-level element because it is a GlimmerComponent.`); break; case 'modifiers': let modifiers = fragmentReason.modifiers.map(m => `{{${m} ...}}`); - _assert(`You cannot use ${ modifiers.join(', ') } in the top-level element of the <${tagName}> template because it is a GlimmerComponent.`); + assert(`You cannot use ${ modifiers.join(', ') } in the top-level element of the <${tagName}> template because it is a GlimmerComponent.`); break; case 'triple-curlies': - _assert(`You cannot use triple curlies (e.g. style={{{ ... }}}) in the top-level element of the <${tagName}> template because it is a GlimmerComponent.`); + assert(`You cannot use triple curlies (e.g. style={{{ ... }}}) in the top-level element of the <${tagName}> template because it is a GlimmerComponent.`); break; } } diff --git a/packages/ember-metal/lib/core.js b/packages/ember-metal/lib/core.js index fe015019ee1..9556ae6ea6d 100644 --- a/packages/ember-metal/lib/core.js +++ b/packages/ember-metal/lib/core.js @@ -45,6 +45,15 @@ Ember.isNamespace = true; Ember.toString = function() { return 'Ember'; }; +// The debug functions are exported to globals with `require` to +// prevent babel-plugin-filter-imports from removing them. +let debugModule = Ember.__loader.require('ember-metal/debug'); +Ember.assert = debugModule.assert; +Ember.warn = debugModule.warn; +Ember.debug = debugModule.debug; +Ember.deprecate = debugModule.deprecate; +Ember.deprecateFunc = debugModule.deprecateFunc; +Ember.runInDebug = debugModule.runInDebug; /** The semantic version. @@ -71,7 +80,7 @@ Ember.VERSION = 'VERSION_STRING_PLACEHOLDER'; if (Ember.ENV) { // do nothing if Ember.ENV is already setup - assert('Ember.ENV should be an object.', 'object' !== typeof Ember.ENV); + Ember.assert('Ember.ENV should be an object.', 'object' !== typeof Ember.ENV); } else if ('undefined' !== typeof EmberENV) { Ember.ENV = EmberENV; } else if ('undefined' !== typeof ENV) { @@ -161,21 +170,4 @@ export { K }; Ember.K = K; //TODO: ES6 GLOBAL TODO - -import { - assert, - warn, - debug, - deprecate, - deprecateFunc, - runInDebug -} from 'ember-metal/debug'; - -Ember.assert = assert; -Ember.warn = warn; -Ember.debug = debug; -Ember.deprecate = deprecate; -Ember.deprecateFunc = deprecateFunc; -Ember.runInDebug = runInDebug; - export default Ember; diff --git a/packages/ember-metal/lib/mixin.js b/packages/ember-metal/lib/mixin.js index cacbd5cd997..e80d99c1fa9 100644 --- a/packages/ember-metal/lib/mixin.js +++ b/packages/ember-metal/lib/mixin.js @@ -163,11 +163,8 @@ function applyMergedProperties(obj, key, value, values) { var baseValue = values[key] || obj[key]; runInDebug(function() { - // TODO: Remove this hack when defeatureify is removed. - let _assert = assert; - if (Array.isArray(value)) { // use conditional to avoid stringifying every time - _assert(`You passed in \`${JSON.stringify(value)}\` as the value for \`${key}\` but \`${key}\` cannot be an Array`, false); + assert(`You passed in \`${JSON.stringify(value)}\` as the value for \`${key}\` but \`${key}\` cannot be an Array`, false); } });