SlideShare a Scribd company logo
1 of 51
Download to read offline
YOUR CODE IS NOT A STRING
INGVAR STEPANYAN
YOUR CODE IS NOT A STRING
SOURCE MAPS - EPIC WIN IN DEBUGGING
YOUR CODE IS NOT A STRING
SOURCE MAPS - EPIC WIN IN DEBUGGING
YOUR CODE IS NOT A STRING
BUILDERS - EPIC FAIL FOR DEBUGGING
umdify:
// UMD definition
output += '(function(root, factory) {n';
output += ' if (typeof define === "function" && define.amd) {n';
output += ' define([' + depNames.join(', ') + '], factory);n';
output += ' } else if (typeof exports === "object") {n';
output += ' module.exports = factory(require);n';
…
YOUR CODE IS NOT A STRING
BUILDERS - EPIC FAIL FOR DEBUGGING
grunt-amd-wrap:
var srcText = grunt.file.read(file.src[0]);
var destText = amdWrap(srcText);
YOUR CODE IS NOT A STRING
BUILDERS - EPIC FAIL FOR DEBUGGING
super-duper-universal-transformer:
function transform(srcText) {
return 'var answer = 42;';
}
IT HAS A SOUL
YOUR CODE IS NOT A STRING
YOUR CODE IS NOT A STRING
YOU ARE PERFORMING PARSING RIGHT NOW
YOUR CODE IS NOT A STRING
YOU ARE PERFORMING PARSING RIGHT NOW
YOUR CODE IS NOT A STRING
WE ARE ALL PARSERS
In computer science, an abstract syntax tree (AST), or just

syntax tree, is a tree representation of the abstract syntactic

structure of source code written in a programming

language. Each node of the tree denotes a construct

occurring in the source code.
The syntax is "abstract" in not representing every detail

appearing in the real syntax. For instance, grouping

parentheses are implicit in the tree structure, and a syntactic

construct like an if-condition-then expression may be

denoted by means of a single node with three branches.
YOUR CODE IS NOT A STRING
WE ARE ALL PARSERS
In computer science, an abstract syntax tree (AST), or just

syntax tree, is a tree representation of the abstract syntactic

structure of source code written in a programming

language. Each node of the tree denotes a construct

occurring in the source code.
The syntax is "abstract" in not representing every detail

appearing in the real syntax. For instance, grouping

parentheses are implicit in the tree structure, and a syntactic

construct like an if-condition-then expression may be

denoted by means of a single node with three branches.
Paragraphs
YOUR CODE IS NOT A STRING
WE ARE ALL PARSERS
In computer science, an abstract syntax tree (AST), or just

syntax tree, is a tree representation of the abstract syntactic

structure of source code written in a programming

language. Each node of the tree denotes a construct

occurring in the source code.
The syntax is "abstract" in not representing every detail

appearing in the real syntax. For instance, grouping

parentheses are implicit in the tree structure, and a syntactic

construct like an if-condition-then expression may be

denoted by means of a single node with three branches.
Paragraphs
Sentences
YOUR CODE IS NOT A STRING
WE ARE ALL PARSERS
In computer science, an abstract syntax tree (AST), or just
syntax tree, is a tree representation of the abstract syntactic 

structure of source code written in a programming
language. Each node of the tree denotes a construct

occurring in the source code.
The syntax is "abstract" in not representing every detail

appearing in the real syntax. For instance, grouping

parentheses are implicit in the tree structure, and a syntactic

construct like an if-condition-then expression may be

denoted by means of a single node with three branches.
Paragraphs
Words and Punctuators
YOUR CODE IS NOT A STRING
HOW DO WE READ TEXTS?
WORDS AND PUNCTUATION SENTENCES PARAGRAPHSPHRASES
YOUR CODE IS NOT A STRING
HOW DO WE READ CODE?
WORDS AND PUNCTUATION STATEMENTS FUNCTIONSEXPRESSIONS
YOUR CODE IS NOT A STRING
HOW DO COMPILERS READ CODE?
WORDS AND PUNCTUATION STATEMENTS FUNCTIONSEXPRESSIONS
YOUR CODE IS NOT A STRING
HOW DO COMPILERS READ CODE?
WORDS AND PUNCTUATION STATEMENTS FUNCTIONSEXPRESSIONS
LEXING PARSING
(TOKENS) (SYNTACTIC NODES)
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
var answer = 42;
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
76 61 72 20 61 6E 73 77 65 72 20 3D 20 34 32 3B
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ v
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ va
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
‣ a
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
‣ an
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
‣ ans
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
‣ answ
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
‣ answe
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
‣ answer
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
‣ answer
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
‣ answer
‣ =
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
‣ answer
‣ =
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
‣ answer
‣ =
‣ 4
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
‣ answer
‣ =
‣ 42
YOUR CODE IS NOT A STRING
LEXING INTO TOKENS
v a r a n s w e r = 4 2 ;
‣ var
‣ answer
‣ =
‣ 42
‣ ;
YOUR CODE IS NOT A STRING
PARSING INTO SYNTAX TREE
‣ var
‣ answer
‣ =
‣ 42
‣ ;
Literal
Identifier
VariableDeclarator VariableDeclaration
YOUR CODE IS NOT A STRING
FILE-BASED BUILDERS
Transforming
AST
Generating
code
Parsing
code
Reading
file
Writing
file
Plugin
YOUR CODE IS NOT A STRING
STREAMING BUILDERS
Transforming
AST
Generating
code
Parsing
code
Reading
file
Writing
file
Plugin
YOUR CODE IS NOT A STRING
TRANSPILERS
Transforming
AST
Generating
code
Parsing
code
Reading
file
Writing
file
Plugin
YOUR CODE IS NOT A STRING
AST TOOLING
▸ Minifiers (UglifyJS supports transforming AST)
▸ Linters (you can write own rules for ESLint!)
▸ Babel (you can write own transpiler plugins!)
▸ Facebook Codemod (you can patch entire codebase!)
▸ Any-to-JS compilers (CoffeeScriptRedux, JSX, …)
▸ Bundlers (WebPack, Browserify combine ASTs)
YOUR CODE IS NOT A STRING
HOMOICONICITY (CODE == AST)
(+ (+ 2 3) 7)
YOUR CODE IS NOT A STRING
HOMOICONICITY (CODE == AST)
<html>
<head>
<title>your title here</title>
</head>
<body bgcolor="ffffff">
<center>
<img src="clouds.jpg" align="bottom" />
</center>
<hr />
<a href="http://somegreatsite.com">link name</a> is a link
<h1>this is a header</h1>
<h2>this is a medium header</h2>
<a href="mailto:support@yourcompany.com">support@yourcompany.com</a>
</body>
</html>
YOUR CODE IS NOT A STRING
ECMASCRIPT SYNTAX SPEC
http://rreverser.com/ecmascript-syntax-graph/
YOUR CODE IS NOT A STRING
ECMASCRIPT SYNTAX SPEC
YOUR CODE IS NOT A STRING
PARSERS PRODUCING JAVASCRIPT ASTS
‣ JavaScript
‣ SpiderMonkey: Reflect.parse – Mozilla's Parser API
‣ Esprima – most popular ECMAScript parser in JS
‣ Acorn – faster alternative ECMAScript parser in JS
‣ UglifyJS – has own parser with custom AST format
‣ Traceur – has ES6 parser that can be used separately as well
‣ …
‣ CoffeeScript
‣ CoffeeScriptRedux – rewrite of CS compiler that internally uses CS AST with conversion
to JS AST
‣ JSX
‣ esprima-fb – Facebook's fork of Esprima Harmony branch
YOUR CODE IS NOT A STRING
SPIDERMONKEY PARSER API
YOUR CODE IS NOT A STRING
ESTREE - JAVASCRIPT AST SPECIFICATION
YOUR CODE IS NOT A STRING
ESTREE - JAVASCRIPT AST SPECIFICATION
https://github.com/estree/estree
‣ Literal { value, raw }
‣ Identifier { name }
‣ MemberExpression { object, property, computed }
‣ BinaryExpression { left, operator, right }
‣ …
YOUR CODE IS NOT A STRING
ASTEXPLORER - AST PLAYGROUND
http://astexplorer.net/
YOUR CODE IS NOT A STRING
BABEL PLUGIN TEMPLATE
https://github.com/RReverser/babel-plugin-hello-world
QUESTIONS?
@RReverser

More Related Content

What's hot

Creating own language made easy
Creating own language made easyCreating own language made easy
Creating own language made easyIngvar Stepanyan
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016Manoj Kumar
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Nikita Popov
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation JavascriptRamesh Nair
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Fwdays
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?Nikita Popov
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP GeneratorsMark Baker
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.boyney123
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...Fwdays
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeCory Forsyth
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRaimonds Simanovskis
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Nikita Popov
 
PHP Performance Trivia
PHP Performance TriviaPHP Performance Trivia
PHP Performance TriviaNikita Popov
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Nikita Popov
 
Crafting beautiful software
Crafting beautiful softwareCrafting beautiful software
Crafting beautiful softwareJorn Oomen
 
Proxies are Awesome!
Proxies are Awesome!Proxies are Awesome!
Proxies are Awesome!Brendan Eich
 
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014Susan Potter
 

What's hot (20)

Creating own language made easy
Creating own language made easyCreating own language made easy
Creating own language made easy
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to Come
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
 
Rails on Oracle 2011
Rails on Oracle 2011Rails on Oracle 2011
Rails on Oracle 2011
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8
 
PHP Performance Trivia
PHP Performance TriviaPHP Performance Trivia
PHP Performance Trivia
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
Crafting beautiful software
Crafting beautiful softwareCrafting beautiful software
Crafting beautiful software
 
Proxies are Awesome!
Proxies are Awesome!Proxies are Awesome!
Proxies are Awesome!
 
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
 

Similar to Your code is not a string

Effective codereview | Dave Liddament | CODEiD
Effective codereview | Dave Liddament | CODEiDEffective codereview | Dave Liddament | CODEiD
Effective codereview | Dave Liddament | CODEiDCODEiD PHP Community
 
Into to DBI with DBD::Oracle
Into to DBI with DBD::OracleInto to DBI with DBD::Oracle
Into to DBI with DBD::Oraclebyterock
 
Juggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDBJuggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDBDavid Golden
 
Questioning the status quo
Questioning the status quoQuestioning the status quo
Questioning the status quoIvano Pagano
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottO'Reilly Media
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Developmentwolframkriesing
 
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)Mark Wilkinson
 
OSCON TALK: Becoming Friends with Cassandra and Spark
OSCON TALK: Becoming Friends with Cassandra and SparkOSCON TALK: Becoming Friends with Cassandra and Spark
OSCON TALK: Becoming Friends with Cassandra and SparkDani Traphagen
 
An OCaml newbie meets Camlp4 parser
An OCaml newbie meets Camlp4 parserAn OCaml newbie meets Camlp4 parser
An OCaml newbie meets Camlp4 parserKiwamu Okabe
 
Regular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And BeyondRegular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And BeyondMax Shirshin
 
03 introduction to graph databases
03   introduction to graph databases03   introduction to graph databases
03 introduction to graph databasesNeo4j
 
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...Adam Mukharil Bachtiar
 
Dev in Santos - Como NÃO fazer pesquisas usando LIKE
Dev in Santos - Como NÃO fazer pesquisas usando LIKEDev in Santos - Como NÃO fazer pesquisas usando LIKE
Dev in Santos - Como NÃO fazer pesquisas usando LIKEFabio Akita
 
Helvetia
HelvetiaHelvetia
HelvetiaESUG
 
Fundamental Unicode in Perl
Fundamental Unicode in PerlFundamental Unicode in Perl
Fundamental Unicode in PerlNova Patch
 
Tips And Tricks For Bioinformatics Software Engineering
Tips And Tricks For Bioinformatics Software EngineeringTips And Tricks For Bioinformatics Software Engineering
Tips And Tricks For Bioinformatics Software Engineeringjtdudley
 
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/ibrettflorio
 

Similar to Your code is not a string (20)

Effective codereview | Dave Liddament | CODEiD
Effective codereview | Dave Liddament | CODEiDEffective codereview | Dave Liddament | CODEiD
Effective codereview | Dave Liddament | CODEiD
 
Into to DBI with DBD::Oracle
Into to DBI with DBD::OracleInto to DBI with DBD::Oracle
Into to DBI with DBD::Oracle
 
Juggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDBJuggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDB
 
Questioning the status quo
Questioning the status quoQuestioning the status quo
Questioning the status quo
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
 
Php 2
Php 2Php 2
Php 2
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Development
 
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
 
OSCON TALK: Becoming Friends with Cassandra and Spark
OSCON TALK: Becoming Friends with Cassandra and SparkOSCON TALK: Becoming Friends with Cassandra and Spark
OSCON TALK: Becoming Friends with Cassandra and Spark
 
An OCaml newbie meets Camlp4 parser
An OCaml newbie meets Camlp4 parserAn OCaml newbie meets Camlp4 parser
An OCaml newbie meets Camlp4 parser
 
Regular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And BeyondRegular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And Beyond
 
03 introduction to graph databases
03   introduction to graph databases03   introduction to graph databases
03 introduction to graph databases
 
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
 
Dev in Santos - Como NÃO fazer pesquisas usando LIKE
Dev in Santos - Como NÃO fazer pesquisas usando LIKEDev in Santos - Como NÃO fazer pesquisas usando LIKE
Dev in Santos - Como NÃO fazer pesquisas usando LIKE
 
Helvetia
HelvetiaHelvetia
Helvetia
 
Fundamental Unicode in Perl
Fundamental Unicode in PerlFundamental Unicode in Perl
Fundamental Unicode in Perl
 
Tips And Tricks For Bioinformatics Software Engineering
Tips And Tricks For Bioinformatics Software EngineeringTips And Tricks For Bioinformatics Software Engineering
Tips And Tricks For Bioinformatics Software Engineering
 
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
 
Javascript2839
Javascript2839Javascript2839
Javascript2839
 
Json
JsonJson
Json
 

More from Ingvar Stepanyan

A very quick intro to astrophotography
A very quick intro to astrophotographyA very quick intro to astrophotography
A very quick intro to astrophotographyIngvar Stepanyan
 
Asyncifying WebAssembly for the modern Web
Asyncifying WebAssembly for the modern WebAsyncifying WebAssembly for the modern Web
Asyncifying WebAssembly for the modern WebIngvar Stepanyan
 
How I tried to compile JavaScript
How I tried to compile JavaScriptHow I tried to compile JavaScript
How I tried to compile JavaScriptIngvar Stepanyan
 

More from Ingvar Stepanyan (6)

A very quick intro to astrophotography
A very quick intro to astrophotographyA very quick intro to astrophotography
A very quick intro to astrophotography
 
Asyncifying WebAssembly for the modern Web
Asyncifying WebAssembly for the modern WebAsyncifying WebAssembly for the modern Web
Asyncifying WebAssembly for the modern Web
 
How I tried to compile JavaScript
How I tried to compile JavaScriptHow I tried to compile JavaScript
How I tried to compile JavaScript
 
es6.concurrency()
es6.concurrency()es6.concurrency()
es6.concurrency()
 
React for WinRT apps
React for WinRT appsReact for WinRT apps
React for WinRT apps
 
JS: Audio Data Processing
JS: Audio Data ProcessingJS: Audio Data Processing
JS: Audio Data Processing
 

Recently uploaded

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Recently uploaded (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Your code is not a string

  • 1. YOUR CODE IS NOT A STRING INGVAR STEPANYAN
  • 2. YOUR CODE IS NOT A STRING SOURCE MAPS - EPIC WIN IN DEBUGGING
  • 3. YOUR CODE IS NOT A STRING SOURCE MAPS - EPIC WIN IN DEBUGGING
  • 4. YOUR CODE IS NOT A STRING BUILDERS - EPIC FAIL FOR DEBUGGING umdify: // UMD definition output += '(function(root, factory) {n'; output += ' if (typeof define === "function" && define.amd) {n'; output += ' define([' + depNames.join(', ') + '], factory);n'; output += ' } else if (typeof exports === "object") {n'; output += ' module.exports = factory(require);n'; …
  • 5. YOUR CODE IS NOT A STRING BUILDERS - EPIC FAIL FOR DEBUGGING grunt-amd-wrap: var srcText = grunt.file.read(file.src[0]); var destText = amdWrap(srcText);
  • 6. YOUR CODE IS NOT A STRING BUILDERS - EPIC FAIL FOR DEBUGGING super-duper-universal-transformer: function transform(srcText) { return 'var answer = 42;'; }
  • 7. IT HAS A SOUL YOUR CODE IS NOT A STRING
  • 8. YOUR CODE IS NOT A STRING YOU ARE PERFORMING PARSING RIGHT NOW
  • 9. YOUR CODE IS NOT A STRING YOU ARE PERFORMING PARSING RIGHT NOW
  • 10. YOUR CODE IS NOT A STRING WE ARE ALL PARSERS In computer science, an abstract syntax tree (AST), or just
 syntax tree, is a tree representation of the abstract syntactic
 structure of source code written in a programming
 language. Each node of the tree denotes a construct
 occurring in the source code. The syntax is "abstract" in not representing every detail
 appearing in the real syntax. For instance, grouping
 parentheses are implicit in the tree structure, and a syntactic
 construct like an if-condition-then expression may be
 denoted by means of a single node with three branches.
  • 11. YOUR CODE IS NOT A STRING WE ARE ALL PARSERS In computer science, an abstract syntax tree (AST), or just
 syntax tree, is a tree representation of the abstract syntactic
 structure of source code written in a programming
 language. Each node of the tree denotes a construct
 occurring in the source code. The syntax is "abstract" in not representing every detail
 appearing in the real syntax. For instance, grouping
 parentheses are implicit in the tree structure, and a syntactic
 construct like an if-condition-then expression may be
 denoted by means of a single node with three branches. Paragraphs
  • 12. YOUR CODE IS NOT A STRING WE ARE ALL PARSERS In computer science, an abstract syntax tree (AST), or just
 syntax tree, is a tree representation of the abstract syntactic
 structure of source code written in a programming
 language. Each node of the tree denotes a construct
 occurring in the source code. The syntax is "abstract" in not representing every detail
 appearing in the real syntax. For instance, grouping
 parentheses are implicit in the tree structure, and a syntactic
 construct like an if-condition-then expression may be
 denoted by means of a single node with three branches. Paragraphs Sentences
  • 13. YOUR CODE IS NOT A STRING WE ARE ALL PARSERS In computer science, an abstract syntax tree (AST), or just syntax tree, is a tree representation of the abstract syntactic 
 structure of source code written in a programming language. Each node of the tree denotes a construct
 occurring in the source code. The syntax is "abstract" in not representing every detail
 appearing in the real syntax. For instance, grouping
 parentheses are implicit in the tree structure, and a syntactic
 construct like an if-condition-then expression may be
 denoted by means of a single node with three branches. Paragraphs Words and Punctuators
  • 14. YOUR CODE IS NOT A STRING HOW DO WE READ TEXTS? WORDS AND PUNCTUATION SENTENCES PARAGRAPHSPHRASES
  • 15. YOUR CODE IS NOT A STRING HOW DO WE READ CODE? WORDS AND PUNCTUATION STATEMENTS FUNCTIONSEXPRESSIONS
  • 16. YOUR CODE IS NOT A STRING HOW DO COMPILERS READ CODE? WORDS AND PUNCTUATION STATEMENTS FUNCTIONSEXPRESSIONS
  • 17. YOUR CODE IS NOT A STRING HOW DO COMPILERS READ CODE? WORDS AND PUNCTUATION STATEMENTS FUNCTIONSEXPRESSIONS LEXING PARSING (TOKENS) (SYNTACTIC NODES)
  • 18. YOUR CODE IS NOT A STRING LEXING INTO TOKENS var answer = 42;
  • 19. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; 76 61 72 20 61 6E 73 77 65 72 20 3D 20 34 32 3B
  • 20. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ v
  • 21. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ va
  • 22. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var
  • 23. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var
  • 24. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var ‣ a
  • 25. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var ‣ an
  • 26. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var ‣ ans
  • 27. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var ‣ answ
  • 28. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var ‣ answe
  • 29. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var ‣ answer
  • 30. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var ‣ answer
  • 31. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var ‣ answer ‣ =
  • 32. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var ‣ answer ‣ =
  • 33. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var ‣ answer ‣ = ‣ 4
  • 34. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var ‣ answer ‣ = ‣ 42
  • 35. YOUR CODE IS NOT A STRING LEXING INTO TOKENS v a r a n s w e r = 4 2 ; ‣ var ‣ answer ‣ = ‣ 42 ‣ ;
  • 36. YOUR CODE IS NOT A STRING PARSING INTO SYNTAX TREE ‣ var ‣ answer ‣ = ‣ 42 ‣ ; Literal Identifier VariableDeclarator VariableDeclaration
  • 37. YOUR CODE IS NOT A STRING FILE-BASED BUILDERS Transforming AST Generating code Parsing code Reading file Writing file Plugin
  • 38. YOUR CODE IS NOT A STRING STREAMING BUILDERS Transforming AST Generating code Parsing code Reading file Writing file Plugin
  • 39. YOUR CODE IS NOT A STRING TRANSPILERS Transforming AST Generating code Parsing code Reading file Writing file Plugin
  • 40. YOUR CODE IS NOT A STRING AST TOOLING ▸ Minifiers (UglifyJS supports transforming AST) ▸ Linters (you can write own rules for ESLint!) ▸ Babel (you can write own transpiler plugins!) ▸ Facebook Codemod (you can patch entire codebase!) ▸ Any-to-JS compilers (CoffeeScriptRedux, JSX, …) ▸ Bundlers (WebPack, Browserify combine ASTs)
  • 41. YOUR CODE IS NOT A STRING HOMOICONICITY (CODE == AST) (+ (+ 2 3) 7)
  • 42. YOUR CODE IS NOT A STRING HOMOICONICITY (CODE == AST) <html> <head> <title>your title here</title> </head> <body bgcolor="ffffff"> <center> <img src="clouds.jpg" align="bottom" /> </center> <hr /> <a href="http://somegreatsite.com">link name</a> is a link <h1>this is a header</h1> <h2>this is a medium header</h2> <a href="mailto:support@yourcompany.com">support@yourcompany.com</a> </body> </html>
  • 43. YOUR CODE IS NOT A STRING ECMASCRIPT SYNTAX SPEC http://rreverser.com/ecmascript-syntax-graph/
  • 44. YOUR CODE IS NOT A STRING ECMASCRIPT SYNTAX SPEC
  • 45. YOUR CODE IS NOT A STRING PARSERS PRODUCING JAVASCRIPT ASTS ‣ JavaScript ‣ SpiderMonkey: Reflect.parse – Mozilla's Parser API ‣ Esprima – most popular ECMAScript parser in JS ‣ Acorn – faster alternative ECMAScript parser in JS ‣ UglifyJS – has own parser with custom AST format ‣ Traceur – has ES6 parser that can be used separately as well ‣ … ‣ CoffeeScript ‣ CoffeeScriptRedux – rewrite of CS compiler that internally uses CS AST with conversion to JS AST ‣ JSX ‣ esprima-fb – Facebook's fork of Esprima Harmony branch
  • 46. YOUR CODE IS NOT A STRING SPIDERMONKEY PARSER API
  • 47. YOUR CODE IS NOT A STRING ESTREE - JAVASCRIPT AST SPECIFICATION
  • 48. YOUR CODE IS NOT A STRING ESTREE - JAVASCRIPT AST SPECIFICATION https://github.com/estree/estree ‣ Literal { value, raw } ‣ Identifier { name } ‣ MemberExpression { object, property, computed } ‣ BinaryExpression { left, operator, right } ‣ …
  • 49. YOUR CODE IS NOT A STRING ASTEXPLORER - AST PLAYGROUND http://astexplorer.net/
  • 50. YOUR CODE IS NOT A STRING BABEL PLUGIN TEMPLATE https://github.com/RReverser/babel-plugin-hello-world