babel-plugin-debug-macros's Issues
warn() arguments are not being transpiled
warn(...arguments);
is apparently being transpiled to
(false && _ember.default.warn(...arguments));
but ...arguments
is ES6 code, which ember-cli-uglify@1
is not able to handle.
see mainmatter/ember-simple-auth#1443
/cc @rwjblue
Not functional in Node 4.
- Add Node 4 to CI.
- Add additional babel plugins (or swap to babel-preset-env) to support node 4.
Investigate Svelte
Investigate creating a contract for consumers to explicitly strip deprecations within a specific semver range.
Handle `CallExpression` for debug macros.
Currently, we are handling only ExpressionStatement
's for debug macro replacement. Unfortunately, the following do not get processed (since they do not include an ExpressionStatement
):
function foo() {
return assert(false, 'derp'); // ReturnStatement
}
let qux = () => assert(false, 'herp'); // ArrowFunctionExpression
This is the underlying issue in emberjs/ember-cli-babel#168.
Modify `deprecate` debug helper to handle single arg.
This should not throw (though Ember will issue a deprecation for not passing the options hash):
import { deprecate } from '@ember/debug';
deprecate('some message');
Currently the following (lovely) error is thrown:
TypeError: -private/system/store.js: Property expression of ParenthesizedExpression expected node to be of a type ["Expression"] but instead got null
at Object.validate (/Users/rjackson/src/open-source/ember-data/node_modules/babel-types/lib/definitions/index.js:109:13)
at validate (/Users/rjackson/src/open-source/ember-data/node_modules/babel-types/lib/index.js:505:9)
at Object.builder (/Users/rjackson/src/open-source/ember-data/node_modules/babel-types/lib/index.js:466:7)
at Builder.deprecate (/Users/rjackson/src/open-source/ember-data/node_modules/babel-plugin-debug-macros/dist/lib/utils/builder.js:187:92)
at Macros.build (/Users/rjackson/src/open-source/ember-data/node_modules/babel-plugin-debug-macros/dist/lib/utils/macros.js:189:36)
at PluginPass.ExpressionStatement (/Users/rjackson/src/open-source/ember-data/node_modules/babel-plugin-debug-macros/dist/index.js:67:27)
at newFn (/Users/rjackson/src/open-source/ember-data/node_modules/babel-traverse/lib/visitors.js:276:21)
at NodePath._call (/Users/rjackson/src/open-source/ember-data/node_modules/babel-traverse/lib/path/context.js:76:18)
at NodePath.call (/Users/rjackson/src/open-source/ember-data/node_modules/babel-traverse/lib/path/context.js:48:17)
at NodePath.visit (/Users/rjackson/src/open-source/ember-data/node_modules/babel-traverse/lib/path/context.js:105:12)
Move to ember-cli org?
Thoughts?
Emits deprecations for `window.Ember` usage after transpilation
Ember 3.27+ emits a deprecation when accessing window.Ember
. At the moment, our transpilation output emits:
Instead, we should use the import that the original code used.
Make sure sourcemaps aren't fubar
Introduce a "externalHelpers" API
Introduce a "externalHelpers" API that allows for mocking out macros for things like testing.
Strip import statement if all imports are removed.
Currently, given:
import { SOME_FLAG } from 'blah/features';
if (SOME_FLAG) {
console.log('whatever');
}
With this config:
{
plugins: [
['babel-debug-macros', {
features: {
name: 'blah',
source: 'blah/features',
flags: { SOME_FLAG: true }
},
}]
]
}
We remove the usage of SOME_FLAG
, but leave the import statement. This forces us to also emit a blah/features
module even if we never have runtime enableable features.
IMO, we should remove imports if they are no longer used...
Running ember-server, seeing an error
Started getting this error recently on my project, just when running ember s
though others don't get it. Any ideas?
The Broccoli Plugin: [Funnel] failed with:
Error: ember-data/-debug/index.js: You must specify envFlags.flags.DEBUG at minimum.
at normalizeOptions (<redacted>/node_modules/babel-plugin-debug-macros/dist/lib/utils/normalize-options.js:74:11)
at PluginPass.enter (<redacted>/node_modules/babel-plugin-debug-macros/dist/index.js:33:60)
Wrong transpilation when optional chaining is used in `assert()`
I have this code:
assert('Need profile data', this.args.window.profile?.data);
When optional chaining is not transpiled, things work fine. The line above is transformed to:
(true && !(this.args.window.profile?.data) && (0, _debug.assert)('Need profile data', this.args.window.profile?.data));
However some automated dependency updates including most Babel stuff changed behavior, in that optional chaining is now transpiled, I believe due to some bug in Chrome, see babel/babel#13145.
But now the transform yields this broken code:
var _this$args$window$pro;
(true && !(_this$args$window$pro.data) && (0, _debug.assert)('Need profile data', (_this$args$window$pro = this.args.window.profile) === null || _this$args$window$pro === void 0 ? void 0 : _this$args$window$pro.data));
Which throws with Cannot read properties of undefined (reading 'data')
as at the time the !(_this$args$window$pro.data)
expression is evaluated _this$args$window$pro
is still undefined!
Wrong transpilation for renamed import
Given this reproduction file: https://github.com/simonihmig/ember-warn-transpilation/blob/master/app/utils/warn.js
This is transpiled to:
define('ember-warn-transpilation/utils/warn', ['exports'], function (exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = warn;
function warn() {
(true && Ember.emberWarn(...arguments));
}
});
Where Ember.emberWarn
is obviously not a thing.
Investigate DCE
Investigate if we can DCE early with path.execute
in Babel.
Modify `assert` output to avoid string allocations when no assertions.
We should basically do the same as we do for deprecate
in this regard.
Today, this input:
import { deprecate, assert } from 'whatever';
deprecate('foo bar', somePredicate, { ... });
assert(somePredicate, 'message here');
Transpiles to:
(true && !(somePredicate) && console.warn('foo bar'));
(true && console.assert(somePredicate, 'message here'));
Note that the deprecate
version avoids allocating the string if the predicate is truthy, but the assert
version does not.
We currently have 4 or 5 assertions for every get
/ set
(for example), and it would be nice to make assert
a bit less expensive in debug builds of Ember...
Replaces provided envFlags even if not imported.
Given the following config:
[debugMacros, {
envFlags: {
source: '@glimmer/env-flags',
flags: envFlags
},
debugTools: {
source: '@glimmer/debug'
},
externalizeHelpers: {
module: true
}
}],
And the following module contents (note no imports):
var DEBUG = 'hahaha';
if (DEBUG === 'hahaha') {
// do things
}
The DEBUG
assignment is removed, and the usage is changed to boolean:
if (false === 'hahaha') {
// do things
}
remove `import '@glimmer/env';`
Like ember-cli/babel-plugin-ember-modules-api-polyfill#38 and ember-cli/babel-plugin-ember-modules-api-polyfill#39, import '@glimmer/env';
suffers the same problem and should be removed. It should also be fixed on the 0.1.x series.
_createMacroExpression closes over code that other transforms may edit.
Take for instance the following
assert(`my assertion`, SOME_VAR);
This library will close over SOME_VAR
when building out the transformation _createMacroExpression
. Since the built transformations are not flushed until program exit, other transforms that edit or replace SOME_VAR
will have no affect.
Make feature flagging replacement system more robust.
The current system does not work for the following statements:
if (SOME_FLAG && whatever && whatever) { }
if (!SOME_FLAG) {}
let something = SOME_FLAG ? one : two;
Break This Up Into 3 Plugins
This is getting pretty unwieldy. Should be broken up into the following:
['debug-macros', {
debug: boolean,
source: string,
externalizeHelpers: { module: true, global: string }
],
['feature-flags', { debug: boolean, flags: Object, source: string }]
['svelte', { flags: Object, debug: boolean, source: string }]
Likely need to check if there are other options that each plugin needs.
support runInDebug(() => /* only run in debug mode*/)?
Maybe this already exists, but didn't see the functionality while skimming the source:
usage:
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.