-
Notifications
You must be signed in to change notification settings - Fork 9
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
Minify Templates based on a white list #14
Minify Templates based on a white list #14
Conversation
98c5fd7
to
53dde0b
Compare
93b3586
to
d49229f
Compare
@siva-sundar I'm still seeing tests that have changed. I thought you adjusted the PR? |
Since we are collapsing the |
@siva-sundar that is a separate change though that seems unrelated to the intent of this PR which was adding support for whitelisting components. please note that the amount of changes in this PR make it very hard to review and it is usually much easier for maintainers to review smaller PRs that only change or add single features. |
I have moved the changes other than the whitelisting into a separate PR(#16). Once it is merged, I'll update this PR. |
44fba8f
to
80c7479
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't have much time atm as I'm going on vacation today for a week. I'll have a detailed look once I'm back.
hbs-minifier-plugin.js
Outdated
class BasePlugin { | ||
constructor(env) { | ||
env = env || {}; | ||
this.moduleName = env.moduleName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems unused now
061fc80
to
b23073a
Compare
d306f81
to
d89c2e1
Compare
e84a15b
to
ea4ee45
Compare
@siva-sundar I've rebased your branch on top of all the changes that fixed our CI builds. It seems that some tests are now failing though... 😞 |
@Turbo87 Tests are failing since htmlbars adds text node boundaries (at the begining and the end) of a template file. Currently I am checking for two text nodes here. But for ember <= 2.9.1, there will be an additional textNode created to mark the closeBoundary. Shall I update the test case based on a version check ? |
I've updated the existing tests to essentially |
0e459ea
to
1b517e2
Compare
1b517e2
to
d5ae5e5
Compare
I have updated the test cases. Can you have a look at it? |
hbs-minifier-plugin.js
Outdated
*/ | ||
if (startLoc.line !== 1 || startLoc.column !== 0) { | ||
return ast; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why this is necessary. Isn't the transform()
function only called for top-level elements? The AST traversal should be handled by the traverse()
call below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In ember 2.15, the transform is called for all the Program
Nodes. I am not sure why. Please check this pipeline and the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is a bug in Ember 2.15 that is already fixed again afaik
/cc @rwjblue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Turbo87 Do you want this issue to be patched up or should I keep it as an issue for that particular Ember versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should no guard against that. The transform that we do should be idempotent so the only advantage of this guard should be less work to do for the buggy versions.
hbs-minifier-plugin.js
Outdated
module.exports = HBSMinifierPlugin; | ||
module.exports = function(config) { | ||
config = config || {}; | ||
config = assignDefaultValues(config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am missing the previous default config where (without any configuration) <pre>
elements and the {{#no-minify}}
"component" were skipped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utils/helpers.js
Outdated
} | ||
|
||
|
||
const canTrimBlockStatementContent = function(node, config) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please convert those to named functions instead of const + anonymous function
utils/helpers.js
Outdated
if (config.components.indexOf(componentName) !== -1 || componentName === 'no-minify' || config.components === 'all') { | ||
return false; | ||
} | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be simplified by return
ing the inverse of the existing condition
utils/helpers.js
Outdated
|
||
const assignDefaultValues = function(config) { | ||
config = config || {}; | ||
let elements = config.elements || 'all'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we skipping all
by default?
025f43a
to
3962fb0
Compare
I have updated the PR with the changes mentioned. Please take a look again. |
hbs-minifier-plugin.js
Outdated
static createASTPlugin() { | ||
class BasePlugin { | ||
static createASTPlugin(config) { | ||
config = config || {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think at the point config
should not be optional anymore.
_setupPreprocessorRegistry(app) { | ||
let registry = app.registry; | ||
let options = app.options || {}; | ||
let config = options['ember-hbs-minifier'] || {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the point at which we should apply the config defaults. If config.skip
is not set we set it to { elements: ['pre'], components: ['no-minify'] }
by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, if the user provides a config, he need to pass the defaults (pre
and no-minify
) along with his config like below. Is it ok?
{
skip: {
elements: ['pre', 'div'],
components: ['no-minify', 'my-component']
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I think that makes sense. otherwise it wouldn't be possible to not skip <pre>
.
utils/helpers.js
Outdated
}); | ||
} | ||
|
||
function canTrimUnnecessaryWhiteSpace(value, config) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the method name should in some way suggest that this is handling values of the class
property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to pass in the complete config
here or would config.classes
be enough?
188fd89
to
acdbf90
Compare
Implements #9