Skip to content

Instantly share code, notes, and snippets.

View joshblack's full-sized avatar

Josh Black joshblack

View GitHub Profile

Babel Types, Construction

Identifier

t.identifier: (string) => identifier

Only really useful thing about an identifier is getting its name.

visitor: {
 Identifier(node) {
// Usage
const container = div({
id: 'foo',
style: {
background: 'black',
width: '100px',
height: '100px'
}
});

Importing

Brief writeup on how to import modules in ES2015, what syntax they have, and how we can grab relevant properties from their AST's.

Introduction

In ES2015, we can import modules into a file using an Import Declaration. An Import Declaration takes on the following interface:

interface ImportDeclaration <: ModuleDeclaration {
const box = document.querySelector('div');
animate(box, {
translated: [250, 250],
rotated: 360,
scaled: [2, 2]
}, 1000, scaling);
function scaling(node) {
return animate(node, {
@joshblack
joshblack / babel-types.md
Last active January 1, 2021 23:44
Documentation of all the Babel type methods

Babel Types

Hopefully will be documentation of unclear methods available for Babel Types

  • is
  • isType
  • shallowEqual
  • appendToMemberExpression
  • prependToMemberExpression
  • ensureBlock
@joshblack
joshblack / babel-notes.md
Last active August 29, 2015 14:26
Taking notes while I'm messing around with Babel

Babel Notes

Just personal notes that I'm collecting as I learn more about how to write plugins for babel.

  • Making a property on an object
    • t.property('init', t.identifier('foo'), t.literal('bar'))
    • Not sure why, but the kind of the property is init, second parameter is key of the object, final one is the value
  • Value to node
    • t.valueToNode()
  • Remove a node
@joshblack
joshblack / .babelrc
Last active November 25, 2015 03:28
Whitelist transformers in `.babelrc` for projects
{
"retainLines": true,
"compact": true,
"comments": false,
"whitelist": [
"es6.arrowFunctions",
"es6.blockScoping",
"es6.classes",
"es6.constants",
"es6.destructuring",
{
isJSXAttribute: [Function],
assertJSXAttribute: [Function],
isJSXClosingElement: [Function],
assertJSXClosingElement: [Function],
isJSXElement: [Function],
assertJSXElement: [Function],
isJSXEmptyExpression: [Function],
assertJSXEmptyExpression: [Function],
isJSXExpressionContainer: [Function],