SlideShare a Scribd company logo
Compile like it’s 2017!
Artem Yavorsky
Hell Yeah LLC
Artem Yavorsky
Software Attorney, Hell Yeah LLC
Day 🌞 Night 🌚
…
Артем Яворский "Compile like it's 2017"
Compile like it’s 2017!
Back to 199x-200x
Артем Яворский "Compile like it's 2017"
Background
1995. Mocha -> LiveScript -> Javascript
1997. ECMAScript 1
1998. ECMAScript 2
1999. ECMAScript 3
(regular expressions, try/catch,
formatting for numeric output…)
ECMAScript 4
• classes
• a module system
• optional type annotations, static typing
• generators and iterators
• destructuring assignment
• algebraic data types.
October 2008
• classes
• a module system
• optional type annotations, static typing
• generators and iterators
• destructuring assignment
• algebraic data types.
October 2008
🚫
Артем Яворский "Compile like it's 2017"
2009: ECMAScript 5
•static Object methods:
defineProperty, create, freeze, seal…
•Array.prototype methods
every, some , filter, map, reduce, forEach, indexOf…
•strict mode
•JSON.parse / JSON.stringify
ECMAScript 2015 aka ES6
Default function parameters
Reset parametersSpread operator
Object literal extensions
for..of loopsOctal and binary literals
Template literals
Destructuring
const
let
arrow functions
class
super
generators
typed arrays
Map
Set
WeakMap WeakSet
Proxy
Reflect
Promise
Symbol
Object static methods
Function name property
String.prototype methods
RegExp.prototype properties
Array static methods
Number properties
Array, RegExp, Function, Promise Subclassing
new.target
Артем Яворский "Compile like it's 2017"
Артем Яворский "Compile like it's 2017"
Артем Яворский "Compile like it's 2017"
Compiler!
Артем Яворский "Compile like it's 2017"
Артем Яворский "Compile like it's 2017"
Arrow functions
Classes
Default parameters
Spread
Rest
Block binding
Property method assigment
Modules
Template Literals
Generators
Destructuring assigment
Parse
Compilation stages
Transform Generate
Parse
Lexical
analysis
Syntactic
Parse
Lexical
analysis
Syntactic
Parse
Lexical
analysis
Syntactic
Code Tokens
Артем Яворский "Compile like it's 2017"
Parse
Lexical
analysis
Syntactic
Parse
Lexical
analysis
Syntactic
Tokens
Abstract
Syntax
Tree
Артем Яворский "Compile like it's 2017"
const a = 1;
b(a);
const a = 1;
b(a);
VariableDeclaration VariableDeclarator
ExpressionStatement CallExpression
Program
a
1
b
arguments a
Parse
Compilation stages
Transform Generate
Transform
AST NEW AST
Tree Traversal
VariableDeclaration VariableDeclarator
ExpressionStatement CallExpression
Program
a
1
b
arguments a
1
2
3
4
5
6
7
8 9
Depth first ☝
const a = 1;
b(a);
Visitors
const visitor = {
CallExpression(path) {
…
},
NumericLiteral(path) {
…
},
FunctionDeclaration(path) {
…
}
}
Parse
Compilation stages
Transform Generate
AST Code
astexplorer.net
plugins
export default function ({ types }) {
return {
pre() { … },
visitor: {
BinaryExpression(path) {
// Transform your code
}
},
post() { … },
}
}
Based on the visitor pattern
PLUGINS
Syntax Transform
Don’t change the code
Teach Babel to read code
syntax-flow
syntax-jsx
syntax-object-rest-spread
Teach Babel to transpile code
Code transformation as a result
transform-flow-strip-types
transform-es2015-classes
transform-es2015-for-of
Артем Яворский "Compile like it's 2017"
Not only 6to5
illustrated-algorithms.now.sh
Illustrated algorithms
babel-plugin-trace-execution
"steps": [
{
"highlight": {
"start": 53,
"end": 80
},
"bindings": {
"list": [
"1",
"2",
"3"
],
"low": 0,
"high": 2
}
} //...
]
Simple dynamic analysis
🍹
const singaporeSling = {};
singaporeSling.gin = 40;
singaporeSling.brandy = 30;
singaporeSling.grenadine = 40;
singaporeSling.cointreau = 50;
🤕
singaporeSling.tequila = 150;
singaporeSling.tequila = 150;
singaporeSling.tequila = 150;
_track(singaporeSling, 'tequila', 150);
fromjs.com
Fromjs
CSS in JS preprocessing
styled-components
const Button = styled.button`
font-size: 1em;
background: ${props => props.primary && 'green'};
`
const Button = styled.button`
font-size: 1em;
background: ${props => props.primary && 'green'};
`
RUNTIME
nesting a {&:hover {}}
@global, :global(selector)
:host()
prefixer
validation
const Button = styled.button`
font-size: 1em;
background: ${props => props.primary && 'green'};
`
RUNTIME
nesting a {&:hover {}}
@global, :global(selector)
:host()
prefixer
validation
<Button className="iSDleSN" />
babel-plugin-styled-components
const Button = styled.button`
font-size: 1em;
background: ${props => props.primary && 'green'};
`
COMPILATION
nesting a {&:hover {}}
@global, :global(selector)
:host()
prefixer
validation
bundle.js
•Server-side rendering
•Better debug
•Removes stylis from the runtime
•Reduces bundle size
•Minification
Benefits
(plugins lists)
presets
Артем Яворский "Compile like it's 2017"
{
"presets": [
"react",
"es2015",
"es2016",
"es2017",
"stage-3"
]
}
.babelrc
babel-preset-latest
Артем Яворский "Compile like it's 2017"
ESNEXT -> 5
Артем Яворский "Compile like it's 2017"
Trade-offs
Extra code
Extra time
Extra bugs
• regenerator
ES2015 Plugins
• exponentiation-operator
ES2016 Plugins
• trailing-function-commas
ES2017 Plugins
• function-name
• for-of
• duplicate-keys
• destructuring
• computed-properties
• classes
• block-scoping
• block-scoped-functions
• arrow-functions
• check-es2015-constants
• sticky-regex
• spread
• shorthand-properties
• parameters
• object-super
• literals
• unicode-regex
• typeof-symbol
• template-literals
• async-to-generator
• regenerator
ES2015 Plugins
• exponentiation-operator
ES2016 Plugins
• trailing-function-commas
ES2017 Plugins
• function-name
• for-of
• duplicate-keys
• destructuring
• computed-properties
• classes
• block-scoping
• block-scoped-functions
• arrow-functions
• check-es2015-constants
• sticky-regex
• spread
• shorthand-properties
• parameters
• object-super
• literals
• unicode-regex
• typeof-symbol
• template-literals
• async-to-generator
• regenerator
ES2015 Plugins
• exponentiation-operator
ES2016 Plugins
• trailing-function-commas
ES2017 Plugins
• function-name
• for-of
• duplicate-keys
• destructuring
• computed-properties
• classes
• block-scoping
• block-scoped-functions
• arrow-functions
• check-es2015-constants
• sticky-regex
• spread
• shorthand-properties
• parameters
• object-super
• literals
• unicode-regex
• typeof-symbol
• template-literals
• async-to-generator
• regenerator
ES2015 Plugins
• exponentiation-operator
ES2016 Plugins
• trailing-function-commas
ES2017 Plugins
• function-name
• for-of
• duplicate-keys
• destructuring
• computed-properties
• classes
• block-scoping
• block-scoped-functions
• arrow-functions
• check-es2015-constants
• sticky-regex
• spread
• shorthand-properties
• parameters
• object-super
• literals
• unicode-regex
• typeof-symbol
• template-literals
• async-to-generator
• regenerator
ES2015 Plugins
• exponentiation-operator
ES2016 Plugins
• trailing-function-commas
ES2017 Plugins
• function-name
• for-of
• duplicate-keys
• destructuring
• computed-properties
• classes
• block-scoping
• block-scoped-functions
• arrow-functions
• check-es2015-constants
• sticky-regex
• spread
• shorthand-properties
• parameters
• object-super
• literals
• unicode-regex
• typeof-symbol
• template-literals
• async-to-generator
• regenerator
ES2015 Plugins
• exponentiation-operator
ES2016 Plugins
• trailing-function-commas
ES2017 Plugins
• function-name
• for-of
• duplicate-keys
• destructuring
• computed-properties
• classes
• block-scoping
• block-scoped-functions
• arrow-functions
• check-es2015-constants
• sticky-regex
• spread
• shorthand-properties
• parameters
• object-super
• literals
• unicode-regex
• typeof-symbol
• template-literals
• async-to-generator
• regenerator
ES2015 Plugins
• exponentiation-operator
ES2016 Plugins
• trailing-function-commas
ES2017 Plugins
• function-name
• for-of
• duplicate-keys
• destructuring
• computed-properties
• classes
• block-scoping
• block-scoped-functions
• arrow-functions
• check-es2015-constants
• sticky-regex
• spread
• shorthand-properties
• parameters
• object-super
• literals
• unicode-regex
• typeof-symbol
• template-literals
• async-to-generator
• regenerator
ES2015 Plugins
• exponentiation-operator
ES2016 Plugins
• trailing-function-commas
ES2017 Plugins
• function-name
• for-of
• duplicate-keys
• destructuring
• computed-properties
• classes
• block-scoping
• block-scoped-functions
• arrow-functions
• check-es2015-constants
• sticky-regex
• spread
• shorthand-properties
• parameters
• object-super
• literals
• unicode-regex
• typeof-symbol
• template-literals
• async-to-generator
11
• regenerator
ES2015 Plugins
• exponentiation-operator
ES2016 Plugins
• trailing-function-commas
ES2017 Plugins
• function-name
• for-of
• duplicate-keys
• destructuring
• computed-properties
• classes
• block-scoping
• block-scoped-functions
• arrow-functions
• check-es2015-constants
• sticky-regex
• spread
• shorthand-properties
• parameters
• object-super
• literals
• unicode-regex
• typeof-symbol
• template-literals
• async-to-generator
11
What about Chrome 45 or Safari 8?
Firefox, Chrome, Safari and IE10 browsers all have the
ability to update themselves.
You can be pretty confident that if your code runs on your
browser, it's going to run on your customer's browser too.
Rob Eisenberg, 2014
babel-preset-env
Just set your targets
{
“targets”: {
“node”: 4,
“electron”: 1.5,
“browsers”: [
“safari 10”,
“last 2 chrome versions”,
“> 2%”
]
}
}
{
“targets”: {
“node”: 4,
“electron”: 1.5,
“browsers”: [
“safari 10”,
“last 2 chrome versions”,
“> 2%”
]
}
}
{
“targets”: {
“node”: 4,
“electron”: 1.5,
“browsers”: [
“safari 10”,
“last 2 chrome versions”,
“> 2%”
]
}
}
{
“targets”: {
“node”: 4,
“electron”: 1.5,
“browsers”: [
“safari 10”,
“last 2 chrome versions”,
“> 2%”
]
}
}
It’s like autoprefixer!
Data from ES6 Compat table
kangax.github.io/compat-table
Same targets for all things
browserslist .babelrc .eslintrc
Артем Яворский "Compile like it's 2017"
Артем Яворский "Compile like it's 2017"
Артем Яворский "Compile like it's 2017"
“browserslist”: […]
eslint-plugin-compat
Артем Яворский "Compile like it's 2017"
eslint-plugin-compat
22: navigator.serviceWorker
^^^^^^^^^^^^^
`ServiceWorker` is not supported in IE 11 and
Edge 15 😢
“browserslist”: “last 1 version”
No Errors!
“browserslist”: “chrome 57”
engines/devEngines
docs.npmjs.com/files/package.json#engines
Артем Яворский "Compile like it's 2017"
Артем Яворский "Compile like it's 2017"
{
“engines”: {
“node”: ”>= 4”
}
}
package.json
Uglify JSES6 💔
Артем Яворский "Compile like it's 2017"
SyntaxErrorNo ES6to5
transformations
=
Артем Яворский "Compile like it's 2017"
Uglify JSpreset-env ❤
{
“targets”: {
“uglify”: true
}
}
NODE_ENVpreset-env ❤
DEVELOPMENT PRODUCTION
DEVELOPMENT PRODUCTION
SPEED
DEVELOPMENT PRODUCTION
SPEED RELIABILITY
11
Uglify JS
DEVELOPMENT PRODUCTION
process.env.NODE_ENV === 'production'
? { uglify: true, ie: 11, ... }
: { chrome: 58 };
even create-react-app!
“browsers”: [
“safari 10”,
“chrome 55”,
“> 2%”
]
configuration?
Артем Яворский "Compile like it's 2017"
1000 items
IE 10
(w/ transform)
Chrome 57
(w/o transform)
const 5.6s 0.39s
`foo${bar}` 1.2s 0.39s
var [a] = [b] 5.55s 0.46s
class A extends B 9.01s 0.42s
for..of 13.05s 0.42s
generators 9.16s 0.58s
async/await 41.87s 0.62s
Compilation time
1000 items
IE 10
(w/ transform)
Chrome 57
(w/o transform)
`foo${bar}` 22kb 11kb
class A extends B 255kb 23kb
for..of 602kb 22kb
generators 330kb 29kb
async/await 533kb 35kb
Compilation result size
Артем Яворский "Compile like it's 2017"
Артем Яворский "Compile like it's 2017"
Артем Яворский "Compile like it's 2017"
Артем Яворский "Compile like it's 2017"
Built-ins
Analyze code
import polyfills
Analyze targets
Old browsers
Latest browsers
Trade-offs
Extra code
Extra time
Extra bugs
Trade-offs
Extra code
Extra time
Extra bugs
(at least on the Babel side)
🙄
github.com/babel/babel-preset-env
Thanks!
Artem Yavorsky
yavorsky_
yavorsky

More Related Content

KEY
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
PDF
Ugo Cei Presentation
PPTX
Introduction to Grails Framework
PDF
Ember.js - A JavaScript framework for creating ambitious web applications
PDF
Reactive, component 그리고 angular2
PPT
Django
PPT
Testing Javascript with Jasmine
PDF
Redux. From twitter hype to production
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Ugo Cei Presentation
Introduction to Grails Framework
Ember.js - A JavaScript framework for creating ambitious web applications
Reactive, component 그리고 angular2
Django
Testing Javascript with Jasmine
Redux. From twitter hype to production

What's hot (18)

PDF
Workshop 12: AngularJS Parte I
PDF
"Service Worker: Let Your Web App Feel Like a Native "
PDF
Flex With Rubyamf
PDF
Integrating React.js with PHP projects
PDF
«От экспериментов с инфраструктурой до внедрения в продакшен»​
PPTX
Vue.js + Django - configuración para desarrollo con webpack y HMR
PPTX
Optimizing a large angular application (ng conf)
PDF
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
KEY
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
PPTX
Игорь Фесенко "Web Apps Performance & JavaScript Compilers"
PDF
"How to use TypeORM and stay alive", Andrii Andriiko
PDF
Why Every Tester Should Learn Ruby
PPTX
Workshop 1: Good practices in JavaScript
PPTX
Javascript asynchronous
PDF
ES6: The Awesome Parts
PPTX
Introduction to es6
KEY
Psgi Plack Sfpm
PDF
Lightweight Webservices with Sinatra and RestClient
Workshop 12: AngularJS Parte I
"Service Worker: Let Your Web App Feel Like a Native "
Flex With Rubyamf
Integrating React.js with PHP projects
«От экспериментов с инфраструктурой до внедрения в продакшен»​
Vue.js + Django - configuración para desarrollo con webpack y HMR
Optimizing a large angular application (ng conf)
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Игорь Фесенко "Web Apps Performance & JavaScript Compilers"
"How to use TypeORM and stay alive", Andrii Andriiko
Why Every Tester Should Learn Ruby
Workshop 1: Good practices in JavaScript
Javascript asynchronous
ES6: The Awesome Parts
Introduction to es6
Psgi Plack Sfpm
Lightweight Webservices with Sinatra and RestClient
Ad

Similar to Артем Яворский "Compile like it's 2017" (20)

PDF
RSpec on Rails Tutorial
PDF
Modern front-end Workflow
KEY
Jarv.us Showcase — SenchaCon 2011
PDF
WebNet Conference 2012 - Designing complex applications using html5 and knock...
PDF
前端MVC之BackboneJS
PDF
Padrino - the Godfather of Sinatra
PDF
SproutCore and the Future of Web Apps
PDF
Intro to React
PDF
Learning to rank search results
PDF
Play Framework and Activator
PDF
Scala Frustrations
PPTX
Angular2 for Beginners
PPT
Windows Server 2008 (PowerShell Scripting Uygulamaları)
PDF
Data driven testing using Integrant & Spec
PDF
Angular Weekend
PDF
JavaScript Robotics
PDF
Spring data requery
PDF
Es.next
PDF
ECMAScript.Next ECMAScipt 6
PPTX
Analytics Metrics delivery and ML Feature visualization: Evolution of Data Pl...
RSpec on Rails Tutorial
Modern front-end Workflow
Jarv.us Showcase — SenchaCon 2011
WebNet Conference 2012 - Designing complex applications using html5 and knock...
前端MVC之BackboneJS
Padrino - the Godfather of Sinatra
SproutCore and the Future of Web Apps
Intro to React
Learning to rank search results
Play Framework and Activator
Scala Frustrations
Angular2 for Beginners
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Data driven testing using Integrant & Spec
Angular Weekend
JavaScript Robotics
Spring data requery
Es.next
ECMAScript.Next ECMAScipt 6
Analytics Metrics delivery and ML Feature visualization: Evolution of Data Pl...
Ad

More from Fwdays (20)

PDF
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
PDF
"Effect, Fiber & Schema: tactical and technical characteristics of Effect.ts"...
PPTX
"Computer Use Agents: From SFT to Classic RL", Maksym Shamrai
PPTX
"Як ми переписали Сільпо на Angular", Євген Русаков
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
PDF
"Validation and Observability of AI Agents", Oleksandr Denisyuk
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
PPTX
"Co-Authoring with a Machine: What I Learned from Writing a Book on Generativ...
PPTX
"Human-AI Collaboration Models for Better Decisions, Faster Workflows, and Cr...
PDF
"AI is already here. What will happen to your team (and your role) tomorrow?"...
PPTX
"Is it worth investing in AI in 2025?", Alexander Sharko
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
PDF
"Scaling in space and time with Temporal", Andriy Lupa.pdf
PDF
"Database isolation: how we deal with hundreds of direct connections to the d...
PDF
"Scaling in space and time with Temporal", Andriy Lupa .pdf
PPTX
"Provisioning via DOT-Chain: from catering to drone marketplaces", Volodymyr ...
PPTX
" Observability with Elasticsearch: Best Practices for High-Load Platform", A...
PPTX
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
PPTX
"Istio Ambient Mesh in production: our way from Sidecar to Sidecar-less",Hlib...
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
"Effect, Fiber & Schema: tactical and technical characteristics of Effect.ts"...
"Computer Use Agents: From SFT to Classic RL", Maksym Shamrai
"Як ми переписали Сільпо на Angular", Євген Русаков
"AI Transformation: Directions and Challenges", Pavlo Shaternik
"Validation and Observability of AI Agents", Oleksandr Denisyuk
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
"Co-Authoring with a Machine: What I Learned from Writing a Book on Generativ...
"Human-AI Collaboration Models for Better Decisions, Faster Workflows, and Cr...
"AI is already here. What will happen to your team (and your role) tomorrow?"...
"Is it worth investing in AI in 2025?", Alexander Sharko
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Database isolation: how we deal with hundreds of direct connections to the d...
"Scaling in space and time with Temporal", Andriy Lupa .pdf
"Provisioning via DOT-Chain: from catering to drone marketplaces", Volodymyr ...
" Observability with Elasticsearch: Best Practices for High-Load Platform", A...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"Istio Ambient Mesh in production: our way from Sidecar to Sidecar-less",Hlib...

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Spectroscopy.pptx food analysis technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Electronic commerce courselecture one. Pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Machine learning based COVID-19 study performance prediction
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Cloud computing and distributed systems.
PPTX
MYSQL Presentation for SQL database connectivity
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Programs and apps: productivity, graphics, security and other tools
Unlocking AI with Model Context Protocol (MCP)
Spectroscopy.pptx food analysis technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
Electronic commerce courselecture one. Pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Big Data Technologies - Introduction.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Machine learning based COVID-19 study performance prediction
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Reach Out and Touch Someone: Haptics and Empathic Computing
Spectral efficient network and resource selection model in 5G networks
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Cloud computing and distributed systems.
MYSQL Presentation for SQL database connectivity

Артем Яворский "Compile like it's 2017"