Closed (outdated)
Project:
Drupal core
Version:
8.4.x-dev
Component:
javascript
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
1 Oct 2016 at 04:46 UTC
Updated:
25 Jul 2017 at 17:11 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
nod_I have no opinion on which tool to use for making this happen. If this one is better, make a patch, i'll test and we'll probably change for this :)
Comment #3
nod_Tried it out, looks like it'd be more useful for things like refactoring during version upgrades than use as a tool to compile our JS. I didn't see how we could create a new file from that.
Comment #4
nod_Oh ok, my mistake. You're right we should use that.
Comment #5
nod_This is awesome :) Worked on it today. Confusing to get started but after a while is mostly ok. Attached a codemod that replace calls to jquery each with for of loops (since they support it now).
After applying some codemods from https://github.com/cpojer/js-codemod (no-vars and arrow-function) and mine, the code looks like this (and running eslint --fix):
Before
After
It'll take a while to get all the codemods working but it's definitely worth it. Instant upgrade for any drupal js. the amount of modifications don't require a compilation to work on modern browsers (see https://kangax.github.io/compat-table/es6/).
Comment #6
nod_And maybe the most visible change is in theme functions:
before
after
Comment #7
nod_Added some more changes:
before
after
Some issues with nested .each() in the first rule but it could be manually dealt with, there are about 4 places where it fails on core code.
If you're wondering about the utility of getting rid of .each() call, when #2402103: Add once.js to core lands, it'll be easier to refactor.Not like it's required but I'm happy when we don't use jquery-specific apis. It does help for passing from jquery to native selector, since this is possibleComment #9
wim leersDidn't #2818825: Rename all JS files to *.es6.js and compile them already do this?
Comment #10
wim leersPer #2809281-39: Use ES6 for core JavaScript development, #2880007: Auto-fix ESLint errors and warnings already did this.