Last active
December 4, 2018 04:03
-
-
Save reconbot/5358ab4a532d2f253df0 to your computer and use it in GitHub Desktop.
CommonJS to ES modules test cases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CommonJS to ES modules test cases | |
// Importing | |
var foo = require('bar'); | |
// becomes | |
import foo from 'bar'; | |
require('bar')(foo); | |
// becomes | |
import tempvar from 'bar'; | |
tempvar(foo); | |
var foo = require('bar').foo; | |
// becomes | |
import {foo} from 'bar'; | |
// Exporting | |
module.exports = { //pojo | |
name: 'todd', | |
value: 'person' | |
}; | |
//becomes | |
export var name = 'todd'; | |
export var value = 'person'; | |
export default {name, value}; | |
module.exports = function(){}; // or anything not a pojo | |
//becomes | |
export default function(){}; | |
module.exports.name = 'todd'; | |
module.exports.value = 'person'; | |
// becomes | |
export var name = 'todd'; | |
export var value = 'person'; | |
export default {name, value}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment