Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

Plugin doesn't work with webpack@2.2.0 #31

Open
ma2ciek opened this issue Feb 1, 2017 · 9 comments
Open

Plugin doesn't work with webpack@2.2.0 #31

ma2ciek opened this issue Feb 1, 2017 · 9 comments

Comments

@ma2ciek
Copy link

ma2ciek commented Feb 1, 2017

I'm using webpack@2.2.0 and wanted to take a look at this plugin while working on the ckeditor/ckeditor5#387, but I got into few troubles.

compiler.parser.plugin is deprecated now. So I changed this line into something like this:

compiler.plugin("compilation", function(compilation, params) {
  params.normalModuleFactory.plugin("parser", (parser, options) => {
    parser.plugin("call " + functionName, (expr) => {
       console.log("it works");
    });
  });
});

But unfortunately it seems to be not working now...
Could you provide some info how to fix it?

Regards, Maciek

@codelegant
Copy link

Although it has warning in webpack 2.2.0, but is still worked in my project.

@ma2ciek
Copy link
Author

ma2ciek commented Feb 6, 2017

It turned out that the bug (or feature) was somewhere else.

Webpack parser runs "call fn" callback only when fn is not defined in the code (I'm not sure why).
So when I have

const t = this.t;
t()

the parser doesn't see t invocation.

I have to use t() function later to provide multi-language support and to be able to transform this string later based on that string and additional words (translated string is used as a template).

@rafaelmaruta
Copy link

I'm with this problem too

@josemigg
Copy link

Either do I, anyone knows how to fix it?

@ma2ciek
Copy link
Author

ma2ciek commented Mar 23, 2017

I had to use acorn to be able to create translation service https://github.com/ckeditor/ckeditor5-dev/blob/master/packages/ckeditor5-dev-utils/lib/translations/translationservice.js, but it would be much nicer if the webpack could handle it by itself.

@EcutDavid EcutDavid assigned EcutDavid and unassigned EcutDavid Mar 25, 2017
@joshwiens joshwiens self-assigned this Mar 28, 2017
@timothylombrana
Copy link

@ma2ciek @d3viant0ne noticed it had been a couple weeks since this was last commented on, was hoping to see if there was some kind of resolution? Thanks for the help!

@ma2ciek
Copy link
Author

ma2ciek commented Apr 28, 2017

I had to implement my own solution with usage of the Acorn parser,

@joshwiens
Copy link
Member

@alphapilgrim - There is a 1.0.0-beta.0 build on npm that will solve that particular issue. Keep in mind there is going to be churn on that beta dist-tag for a few weeks.

@mightyaleksey
Copy link
Collaborator

mightyaleksey commented Aug 3, 2017

Webpack parser runs "call fn" callback only when fn is not defined in the code (I'm not sure why).

@ma2ciek looks like it's a current implementation of the webpack's Parser. See:
https://github.com/webpack/webpack/blob/master/lib/Parser.js#L257
https://github.com/webpack/webpack/blob/master/lib/Parser.js#L1100

I'm not sure why you want to replace the calls of defined functions, but looks like to affect them you have to register another callback for the evaluate defined Identifier ${functionName} event and return an evaluated expression (instance of BasicEvaluatedExpression).

Smthing like this:

const BasicEvaluatedExpression = require('webpack/lib/BasicEvaluatedExpression');
// ...
parser.plugin(`evaluate defined Identifier ${name}`, function (expr) {
  return new BasicEvaluatedExpression().setIdentifier(expr.name).setRange(expr.range);
});

@joshwiens joshwiens removed their assignment Aug 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants