Cleaned up babel and added ES7 async

This commit is contained in:
Lukas Obermann
2016-10-31 22:14:58 +01:00
parent 95ff8caede
commit 9a6566c3ca
29481 changed files with 1136811 additions and 100946 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
{
"presets": ["react", "es2015", "stage-1"],
"plugins": ["transform-class-properties", "transform-object-assign", "transform-do-expressions"]
"presets": ["es2015", "react", "stage-1"],
"plugins": ["transform-class-properties", "transform-do-expressions", "transform-object-assign", "transform-object-rest-spread", "transform-runtime"]
}
+1
View File
File diff suppressed because one or more lines are too long
+7654 -2791
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -2,7 +2,7 @@ import AppDispatcher from '../dispatcher/AppDispatcher';
import ActionTypes from '../constants/ActionTypes';
import WebAPIUtils from '../utils/WebAPIUtils';
import createOverlay from '../utils/createOverlay';
import AccountStore from '../stores/core/AccountStore';
import AccountStore from '../stores/AccountStore';
import ForgotUsername from '../components/content/account/ForgotUsername';
import ForgotPassword from '../components/content/account/ForgotPassword';
import Login from '../components/content/account/Login';
+9 -7
View File
@@ -1,6 +1,6 @@
import AppDispatcher from '../dispatcher/AppDispatcher';
import ActionTypes from '../constants/ActionTypes';
import HerolistStore from '../stores/core/HerolistStore';
import HerolistStore from '../stores/HerolistStore';
import reactAlert from '../utils/reactAlert';
var ServerActions = {
@@ -82,11 +82,6 @@ var ServerActions = {
break;
}
},
logoutSuccess: function() {
AppDispatcher.dispatch({
actionType: ActionTypes.LOGOUT_SUCCESS
});
},
receiveAccount: function(callback, name) {
switch (callback) {
case 'false':
@@ -108,7 +103,9 @@ var ServerActions = {
});
break;
default: {
let [ id, heroes ] = JSON.parse(callback);
// let [ id, heroes ] = JSON.parse(callback);
let id = parseInt(callback);
let heroes = [];
AppDispatcher.dispatch({
actionType: ActionTypes.RECEIVE_ACCOUNT,
id, name, heroes
@@ -116,6 +113,11 @@ var ServerActions = {
}
}
},
logoutSuccess: function() {
AppDispatcher.dispatch({
actionType: ActionTypes.LOGOUT_SUCCESS
});
},
changeUsernameSuccess: function(callback) {
switch (callback) {
case 'false':
+1 -1
View File
@@ -2,7 +2,7 @@ import AppDispatcher from '../dispatcher/AppDispatcher';
import ActionTypes from '../constants/ActionTypes';
import reactAlert from '../utils/reactAlert';
import saveHero from '../utils/saveHero';
import AccountStore from '../stores/core/AccountStore';
import AccountStore from '../stores/AccountStore';
var TabActions = {
openTab: function(tab) {
+2 -2
View File
@@ -1,7 +1,7 @@
import Content from './content/Content';
import React, { Component } from 'react';
import TabStore from '../stores/core/TabStore';
import WaitStore from '../stores/core/WaitStore';
import TabStore from '../stores/TabStore';
import WaitStore from '../stores/WaitStore';
class AppController extends Component {
+1 -1
View File
@@ -1,4 +1,4 @@
import VersionStore from '../../../stores/core/VersionStore';
import VersionStore from '../../../stores/VersionStore';
import React, { Component } from 'react';
import Scroll from '../../layout/Scroll';
+1 -1
View File
@@ -1,5 +1,5 @@
import AccountActions from '../../../actions/AccountActions';
import AccountStore from '../../../stores/core/AccountStore';
import AccountStore from '../../../stores/AccountStore';
import BorderButton from '../../layout/BorderButton';
import IconButton from '../../layout/IconButton';
import React, { Component } from 'react';
+3 -3
View File
@@ -1,11 +1,11 @@
import BorderButton from '../../layout/BorderButton';
import Checkbox from '../../layout/Checkbox';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import DisAdvActions from '../../../actions/DisAdvActions';
import DisAdvList from './DisAdvList';
import DisAdvStore from '../../../stores/DisAdvStore';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import RaceStore from '../../../stores/rcp/RaceStore';
import ProfessionStore from '../../../stores/ProfessionStore';
import RaceStore from '../../../stores/RaceStore';
import React, { Component } from 'react';
import Slidein from '../../layout/Slidein';
import TextField from '../../layout/TextField';
@@ -1,11 +1,11 @@
import BorderButton from '../../layout/BorderButton';
import Checkbox from '../../layout/Checkbox';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import DisAdvActions from '../../../actions/DisAdvActions';
import DisAdvList from './DisAdvList';
import DisAdvStore from '../../../stores/DisAdvStore';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import RaceStore from '../../../stores/rcp/RaceStore';
import ProfessionStore from '../../../stores/ProfessionStore';
import RaceStore from '../../../stores/RaceStore';
import React, { Component } from 'react';
import Slidein from '../../layout/Slidein';
import TextField from '../../layout/TextField';
+4 -4
View File
@@ -1,13 +1,13 @@
import APStore from '../../../stores/APStore';
import BorderButton from '../../layout/BorderButton';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import ELStore from '../../../stores/ELStore';
import HerolistActions from '../../../actions/HerolistActions';
import HerolistItem from './HerolistItem';
import HerolistStore from '../../../stores/core/HerolistStore';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import HerolistStore from '../../../stores/HerolistStore';
import ProfessionStore from '../../../stores/ProfessionStore';
import ProfileStore from '../../../stores/ProfileStore';
import RaceStore from '../../../stores/rcp/RaceStore';
import RaceStore from '../../../stores/RaceStore';
import RadioButtonGroup from '../../layout/RadioButtonGroup';
import React, { Component } from 'react';
import Scroll from '../../layout/Scroll';
@@ -1,12 +1,12 @@
import Avatar from '../../layout/Avatar';
import BorderButton from '../../layout/BorderButton';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import HerolistActions from '../../../actions/HerolistActions';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
import ProfessionStore from '../../../stores/ProfessionStore';
import ProfessionVariantStore from '../../../stores/ProfessionVariantStore';
import ProfileStore from '../../../stores/ProfileStore';
import ProgressArc from 'react-progress-arc';
import RaceStore from '../../../stores/rcp/RaceStore';
import RaceStore from '../../../stores/RaceStore';
import React, { PropTypes, Component } from 'react';
import TabActions from '../../../actions/TabActions';
import classNames from 'classnames';
+4 -4
View File
@@ -2,16 +2,16 @@ import AttributeStore from '../../../stores/AttributeStore';
import APStore from '../../../stores/APStore';
import Avatar from '../../layout/Avatar';
import Box from '../../layout/sheets/Box';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import DisAdvStore from '../../../stores/DisAdvStore';
import ELStore from '../../../stores/ELStore';
import LabelBox from '../../layout/sheets/LabelBox';
import MainSheetCalcItem from './MainSheetCalcItem';
import OverviewConstSkills from './OverviewConstSkills';
import Plain from '../../layout/sheets/Plain';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
import RaceStore from '../../../stores/rcp/RaceStore';
import ProfessionStore from '../../../stores/ProfessionStore';
import ProfessionVariantStore from '../../../stores/ProfessionVariantStore';
import RaceStore from '../../../stores/RaceStore';
import React, { Component } from 'react';
import SheetHeader from './SheetHeader';
import TextBox from '../../layout/sheets/TextBox';
+4 -4
View File
@@ -2,16 +2,16 @@ import AttributeStore from '../../../stores/AttributeStore';
import APStore from '../../../stores/APStore';
import Avatar from '../../layout/Avatar';
import Box from '../../layout/sheets/Box';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import DisAdvStore from '../../../stores/DisAdvStore';
import ELStore from '../../../stores/ELStore';
import LabelBox from '../../layout/sheets/LabelBox';
import MainSheetCalcItem from './MainSheetCalcItem';
import OverviewConstSkills from './OverviewConstSkills';
import Plain from '../../layout/sheets/Plain';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
import RaceStore from '../../../stores/rcp/RaceStore';
import ProfessionStore from '../../../stores/ProfessionStore';
import ProfessionVariantStore from '../../../stores/ProfessionVariantStore';
import RaceStore from '../../../stores/RaceStore';
import React, { Component } from 'react';
import SheetHeader from './SheetHeader';
import TextBox from '../../layout/sheets/TextBox';
@@ -2,15 +2,15 @@ import AttributeStore from '../../../stores/AttributeStore';
import APStore from '../../../stores/APStore';
import Avatar from '../../layout/Avatar';
import Box from '../../layout/sheets/Box';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import DisAdvStore from '../../../stores/DisAdvStore';
import ELStore from '../../../stores/ELStore';
import LabelBox from '../../layout/sheets/LabelBox';
import MainSheetCalcItem from './MainSheetCalcItem';
import Plain from '../../layout/sheets/Plain';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
import RaceStore from '../../../stores/rcp/RaceStore';
import ProfessionStore from '../../../stores/ProfessionStore';
import ProfessionVariantStore from '../../../stores/ProfessionVariantStore';
import RaceStore from '../../../stores/RaceStore';
import React, { Component } from 'react';
import SheetHeader from './SheetHeader';
import TextBox from '../../layout/sheets/TextBox';
+4 -4
View File
@@ -1,6 +1,6 @@
import AttributeStore from '../../../stores/AttributeStore';
import APStore from '../../../stores/APStore';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import DisAdvStore from '../../../stores/DisAdvStore';
import ELStore from '../../../stores/ELStore';
import ListStore from '../../../stores/ListStore';
@@ -8,9 +8,9 @@ import MainSheetCalc from './MainSheetCalc';
import MainSheetPersonalData from './MainSheetPersonalData';
import OverviewConstSkills from './OverviewConstSkills';
import ProfileStore from '../../../stores/ProfileStore';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
import RaceStore from '../../../stores/rcp/RaceStore';
import ProfessionStore from '../../../stores/ProfessionStore';
import ProfessionVariantStore from '../../../stores/ProfessionVariantStore';
import RaceStore from '../../../stores/RaceStore';
import React, { Component } from 'react';
import SheetHeader from './SheetHeader';
import SpecialAbilitiesStore from '../../../stores/SpecialAbilitiesStore';
+4 -4
View File
@@ -1,16 +1,16 @@
import Avatar from '../../layout/Avatar';
import APStore from '../../../stores/APStore';
import BorderButton from '../../layout/BorderButton';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import DisAdvStore from '../../../stores/DisAdvStore';
import Dropdown from '../../layout/Dropdown';
import ELStore from '../../../stores/ELStore';
import IconButton from '../../layout/IconButton';
import OverviewConstSkills from './OverviewConstSkills';
import OverviewNameChange from './OverviewNameChange';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
import RaceStore from '../../../stores/rcp/RaceStore';
import ProfessionStore from '../../../stores/ProfessionStore';
import ProfessionVariantStore from '../../../stores/ProfessionVariantStore';
import RaceStore from '../../../stores/RaceStore';
import PhaseStore from '../../../stores/PhaseStore';
import ProfileActions from '../../../actions/ProfileActions';
import ProfileStore from '../../../stores/ProfileStore';
+4 -4
View File
@@ -2,16 +2,16 @@ import AttributeStore from '../../../stores/AttributeStore';
import APStore from '../../../stores/APStore';
import Avatar from '../../layout/Avatar';
import Box from '../../layout/sheets/Box';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import DisAdvStore from '../../../stores/DisAdvStore';
import ELStore from '../../../stores/ELStore';
import LabelBox from '../../layout/sheets/LabelBox';
import MainSheetCalcItem from './MainSheetCalcItem';
import OverviewConstSkills from './OverviewConstSkills';
import Plain from '../../layout/sheets/Plain';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
import RaceStore from '../../../stores/rcp/RaceStore';
import ProfessionStore from '../../../stores/ProfessionStore';
import ProfessionVariantStore from '../../../stores/ProfessionVariantStore';
import RaceStore from '../../../stores/RaceStore';
import React, { Component } from 'react';
import SheetHeader from './SheetHeader';
import TextBox from '../../layout/sheets/TextBox';
@@ -2,16 +2,16 @@ import AttributeStore from '../../../stores/AttributeStore';
import APStore from '../../../stores/APStore';
import Avatar from '../../layout/Avatar';
import Box from '../../layout/sheets/Box';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import DisAdvStore from '../../../stores/DisAdvStore';
import ELStore from '../../../stores/ELStore';
import LabelBox from '../../layout/sheets/LabelBox';
import MainSheetCalcItem from './MainSheetCalcItem';
import OverviewConstSkills from './OverviewConstSkills';
import Plain from '../../layout/sheets/Plain';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
import RaceStore from '../../../stores/rcp/RaceStore';
import ProfessionStore from '../../../stores/ProfessionStore';
import ProfessionVariantStore from '../../../stores/ProfessionVariantStore';
import RaceStore from '../../../stores/RaceStore';
import React, { Component } from 'react';
import SheetHeader from './SheetHeader';
import TextBox from '../../layout/sheets/TextBox';
+1 -1
View File
@@ -4,7 +4,7 @@ import Dropdown from '../../layout/Dropdown';
import RadioButtonGroup from '../../layout/RadioButtonGroup';
import React, { Component, PropTypes } from 'react';
import CultureActions from '../../../actions/CultureActions';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import Scroll from '../../layout/Scroll';
import TalentsStore from '../../../stores/TalentsStore';
import TextField from '../../layout/TextField';
+2 -2
View File
@@ -4,9 +4,9 @@ import Dropdown from '../../layout/Dropdown';
import RadioButtonGroup from '../../layout/RadioButtonGroup';
import React, { Component, PropTypes } from 'react';
import ProfessionActions from '../../../actions/ProfessionActions';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionStore from '../../../stores/ProfessionStore';
import ProfessionVariantActions from '../../../actions/ProfessionVariantActions';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
import ProfessionVariantStore from '../../../stores/ProfessionVariantStore';
import Scroll from '../../layout/Scroll';
import Selections from './Selections';
import TalentsStore from '../../../stores/TalentsStore';
+2 -2
View File
@@ -1,8 +1,8 @@
import Cultures from './Cultures';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import Professions from './Professions';
import Races from './Races';
import RaceStore from '../../../stores/rcp/RaceStore';
import RaceStore from '../../../stores/RaceStore';
import React, { Component } from 'react';
import SubTabs from '../../layout/SubTabs';
+1 -1
View File
@@ -4,7 +4,7 @@ import Dropdown from '../../layout/Dropdown';
import RadioButtonGroup from '../../layout/RadioButtonGroup';
import React, { Component, PropTypes } from 'react';
import RaceActions from '../../../actions/RaceActions';
import RaceStore from '../../../stores/rcp/RaceStore';
import RaceStore from '../../../stores/RaceStore';
import Scroll from '../../layout/Scroll';
import TextField from '../../layout/TextField';
import classNames from 'classnames';
+4 -4
View File
@@ -1,15 +1,15 @@
import AttributeStore from '../../../stores/AttributeStore';
import BorderButton from '../../layout/BorderButton';
import Checkbox from '../../layout/Checkbox';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import Dropdown from '../../layout/Dropdown';
import ListStore from '../../../stores/ListStore';
import RadioButtonGroup from '../../layout/RadioButtonGroup';
import React, { Component, PropTypes } from 'react';
import ProfessionActions from '../../../actions/ProfessionActions';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
import RaceStore from '../../../stores/rcp/RaceStore';
import ProfessionStore from '../../../stores/ProfessionStore';
import ProfessionVariantStore from '../../../stores/ProfessionVariantStore';
import RaceStore from '../../../stores/RaceStore';
import Scroll from '../../layout/Scroll';
import SelectionsCantrips from './SelectionsCantrips';
import SelectionsCt from './SelectionsCt';
+1 -1
View File
@@ -1,6 +1,6 @@
import BorderButton from '../../layout/BorderButton';
import Checkbox from '../../layout/Checkbox';
import CultureStore from '../../../stores/rcp/CultureStore';
import CultureStore from '../../../stores/CultureStore';
import PhaseStore from '../../../stores/PhaseStore';
import RadioButtonGroup from '../../layout/RadioButtonGroup';
import React, { Component } from 'react';
+1 -1
View File
@@ -1,5 +1,5 @@
import AccountActions from '../../actions/AccountActions';
import AccountStore from '../../stores/core/AccountStore';
import AccountStore from '../../stores/AccountStore';
import APStore from '../../stores/APStore';
import Avatar from './Avatar';
import BorderButton from './BorderButton';
+7 -6
View File
@@ -1,12 +1,13 @@
import AppDispatcher from '../dispatcher/AppDispatcher';
import CultureStore from './rcp/CultureStore';
import CultureStore from './CultureStore';
import ELStore from './ELStore';
import { EventEmitter } from 'events';
import ListStore from '../stores/ListStore';
import RaceStore from './rcp/RaceStore';
import ProfessionStore from './rcp/ProfessionStore';
import ProfessionVariantStore from './rcp/ProfessionVariantStore';
import RaceStore from './RaceStore';
import ProfessionStore from './ProfessionStore';
import ProfessionVariantStore from './ProfessionVariantStore';
import ActionTypes from '../constants/ActionTypes';
import iccalc from '../utils/iccalc';
import reactAlert from '../utils/reactAlert';
import reqPurchase from '../utils/reqPurchase';
@@ -162,8 +163,8 @@ var APStore = Object.assign({}, EventEmitter.prototype, {
};
},
getCosts: function(fw, skt, add = true) {
var costs = skt !== undefined ? (fw == 'aktv' ? AKTV[skt - 1] : fw < 13 ? SKT[skt - 1][0] : SKT[skt - 1][fw - 12]) : fw;
getCosts: function(sr, ic, add = true) {
var costs = ic !== undefined ? (sr === 'aktv' ? iccalc.getAC(ic) : iccalc.getIC(ic, sr)) : sr;
if (!add) costs = -costs;
return costs;
},
+1 -1
View File
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
import ELStore from './ELStore';
import ListStore from './ListStore';
import PhaseStore from './PhaseStore';
import RaceStore from './rcp/RaceStore';
import RaceStore from './RaceStore';
import ActionTypes from '../constants/ActionTypes';
import Categories from '../constants/Categories';
+2 -2
View File
@@ -3,8 +3,8 @@ import { EventEmitter } from 'events';
import ELStore from './ELStore';
import ListStore from './ListStore';
import PhaseStore from './PhaseStore';
import ProfessionStore from './rcp/ProfessionStore';
import ProfessionVariantStore from './rcp/ProfessionVariantStore';
import ProfessionStore from './ProfessionStore';
import ProfessionVariantStore from './ProfessionVariantStore';
import ActionTypes from '../constants/ActionTypes';
import Categories from '../constants/Categories';
+1 -1
View File
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
import ELStore from './ELStore';
import ListStore from './ListStore';
import LiturgiesStore from './LiturgiesStore';
import RaceStore from './rcp/RaceStore';
import RaceStore from './RaceStore';
import SpellsStore from './SpellsStore';
import TalentsStore from './TalentsStore';
import ActionTypes from '../constants/ActionTypes';
+9 -80
View File
@@ -4,88 +4,13 @@ import ActionTypes from '../constants/ActionTypes';
// EL = Experience Level
var _el = {
EL_1: {
id: 'EL_1',
name: 'Unerfahren',
ap: 900,
max_attr: 12,
max_skill: 10,
max_combattech: 8,
max_attrsum: 95,
max_spells_liturgies: 8,
max_unfamiliar_spells: 0
},
EL_2: {
id: 'EL_2',
name: 'Durchschnittlich',
ap: 1000,
max_attr: 13,
max_skill: 10,
max_combattech: 10,
max_attrsum: 98,
max_spells_liturgies: 10,
max_unfamiliar_spells: 1
},
EL_3: {
id: 'EL_3',
name: 'Erfahren',
ap: 1100,
max_attr: 14,
max_skill: 10,
max_combattech: 12,
max_attrsum: 100,
max_spells_liturgies: 12,
max_unfamiliar_spells: 2
},
EL_4: {
id: 'EL_4',
name: 'Kompetent',
ap: 1200,
max_attr: 15,
max_skill: 13,
max_combattech: 14,
max_attrsum: 102,
max_spells_liturgies: 14,
max_unfamiliar_spells: 3
},
EL_5: {
id: 'EL_5',
name: 'Meisterlich',
ap: 1400,
max_attr: 16,
max_skill: 16,
max_combattech: 16,
max_attrsum: 105,
max_spells_liturgies: 16,
max_unfamiliar_spells: 4
},
EL_6: {
id: 'EL_6',
name: 'Brilliant',
ap: 1700,
max_attr: 17,
max_skill: 19,
max_combattech: 18,
max_attrsum: 109,
max_spells_liturgies: 18,
max_unfamiliar_spells: 5
},
EL_7: {
id: 'EL_7',
name: 'Legendär',
ap: 2100,
max_attr: 18,
max_skill: 20,
max_combattech: 20,
max_attrsum: 114,
max_spells_liturgies: 20,
max_unfamiliar_spells: 6
}
};
var _el = {};
var _start = 'EL_0';
function _init(el) {
_el = el;
}
function _update(el) {
_start = el;
}
@@ -138,6 +63,10 @@ ELStore.dispatchToken = AppDispatcher.register( function( payload ) {
_update(payload.el);
break;
case ActionTypes.RECEIVE_RAW_LISTS:
_init(payload.el);
break;
default:
return true;
}
+4 -4
View File
@@ -1,11 +1,11 @@
import AppDispatcher from '../dispatcher/AppDispatcher';
import CultureStore from './rcp/CultureStore';
import CultureStore from './CultureStore';
import ELStore from './ELStore';
import { EventEmitter } from 'events';
import ListStore from '../stores/ListStore';
import RaceStore from './rcp/RaceStore';
import ProfessionStore from './rcp/ProfessionStore';
import ProfessionVariantStore from './rcp/ProfessionVariantStore';
import RaceStore from './RaceStore';
import ProfessionStore from './ProfessionStore';
import ProfessionVariantStore from './ProfessionVariantStore';
import ActionTypes from '../constants/ActionTypes';
import reactAlert from '../utils/reactAlert';
import reqPurchase from '../utils/reqPurchase';
+1 -1
View File
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
import ELStore from './ELStore';
import ListStore from './ListStore';
import PhaseStore from './PhaseStore';
import ProfessionStore from './rcp/ProfessionStore';
import ProfessionStore from './ProfessionStore';
import ActionTypes from '../constants/ActionTypes';
import Categories from '../constants/Categories';
+1 -1
View File
@@ -1,7 +1,7 @@
import AppDispatcher from '../dispatcher/AppDispatcher';
import { EventEmitter } from 'events';
import ActionTypes from '../constants/ActionTypes';
import RaceStore from './rcp/RaceStore';
import RaceStore from './RaceStore';
import dice from '../utils/dice';
const HAIRCOLORS = [ 'blauschwarz', 'blond', 'braun', 'dunkelblond', 'dunkelbraun', 'goldblond', 'grau', 'hellblond', 'hellbraun', 'kupferrot', 'mittelblond', 'mittelbraun', 'rot', 'rotblond', 'schneeweiß', 'schwarz', 'silbern', 'weißblond', 'dunkelgrau', 'hellgrau', 'salzweiß', 'silberweiß', 'feuerrot' ];
+3 -3
View File
@@ -1,11 +1,11 @@
import AppDispatcher from '../dispatcher/AppDispatcher';
import CultureStore from './rcp/CultureStore';
import CultureStore from './CultureStore';
import CombatTechniquesStore from './CombatTechniquesStore';
import { EventEmitter } from 'events';
import ListStore from './ListStore';
import PhaseStore from './PhaseStore';
import ProfessionStore from './rcp/ProfessionStore';
import ProfessionVariantStore from './rcp/ProfessionVariantStore';
import ProfessionStore from './ProfessionStore';
import ProfessionVariantStore from './ProfessionVariantStore';
import TalentsStore from './TalentsStore';
import ActionTypes from '../constants/ActionTypes';
import Categories from '../constants/Categories';
+1 -1
View File
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
import ELStore from './ELStore';
import ListStore from './ListStore';
import PhaseStore from './PhaseStore';
import ProfessionStore from './rcp/ProfessionStore';
import ProfessionStore from './ProfessionStore';
import ActionTypes from '../constants/ActionTypes';
import Categories from '../constants/Categories';
+3 -3
View File
@@ -1,11 +1,11 @@
import AppDispatcher from '../dispatcher/AppDispatcher';
import { EventEmitter } from 'events';
import CultureStore from './rcp/CultureStore';
import CultureStore from './CultureStore';
import ELStore from './ELStore';
import ListStore from './ListStore';
import PhaseStore from './PhaseStore';
import ProfessionStore from './rcp/ProfessionStore';
import ProfessionVariantStore from './rcp/ProfessionVariantStore';
import ProfessionStore from './ProfessionStore';
import ProfessionVariantStore from './ProfessionVariantStore';
import ActionTypes from '../constants/ActionTypes';
import Categories from '../constants/Categories';
@@ -43,6 +43,7 @@ WaitStore.dispatchToken = AppDispatcher.register( function( payload ) {
case ActionTypes.WAIT_END:
case ActionTypes.REGISTRATION_SUCCESS:
case ActionTypes.RECEIVE_ACCOUNT:
case ActionTypes.LOGOUT_SUCCESS:
case ActionTypes.CLEAR_ACCOUNT:
case ActionTypes.UPDATE_USERNAME:
case ActionTypes.RECEIVE_RAW_HEROES:
+218 -378
View File
@@ -1,412 +1,252 @@
import ActionTypes from '../constants/ActionTypes';
import AccountActions from '../actions/AccountActions';
import AccountStore from '../stores/core/AccountStore';
import AppDispatcher from '../dispatcher/AppDispatcher';
import AccountStore from '../stores/AccountStore';
import jQuery from 'jQuery';
import ProfileStore from '../stores/ProfileStore';
import React from 'react';
import ReactDOM from 'react-dom';
import request from './request';
import ServerActions from '../actions/ServerActions';
var WebAPIUtils = {
getAllData: function() {
return new Promise(function(){
jQuery.ajax(
{
url: 'DSA5.json',
type: 'GET',
dataType: 'json',
success: function(result) {
ServerActions.receiveLists(result);
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
getAllData: async function() {
try {
let result = await request.get('DSA5.json', 'json');
ServerActions.receiveLists(result);
} catch(e) {
console.log(e);
ServerActions.connectionError(e);
}
},
register: function(email, username, password) {
ServerActions.startLoading();
return new Promise(function(){
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/register.php?e=' + email + '&u=' + username + '&p=' + password,
type: 'GET',
dataType: 'text',
success: function() {
ServerActions.registrationSuccess();
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
register: async function(email, username, password) {
try {
ServerActions.startLoading();
let url = 'php/register.php?e=' + email + '&u=' + username + '&p=' + password;
let result = await request.get(url);
ServerActions.registrationSuccess(result);
} catch(e) {
ServerActions.connectionError(e);
}
},
checkEmail: function(email) {
return new Promise(function(resolve){
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/checkemail.php?e=' + email,
type: 'GET',
dataType: 'text',
success: function(result) {
resolve(result);
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
checkEmail: async function(email) {
try {
let result = await request.get('php/checkemail.php?e=' + email);
return result;
} catch(e) {
ServerActions.connectionError(e);
}
},
checkUsername: function(username) {
return new Promise(function(resolve){
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/checkuser.php?u=' + username,
type: 'GET',
dataType: 'text',
success: function(result) {
resolve(result);
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
checkUsername: async function(username) {
try {
let result = await request.get('php/checkuser.php?e=' + username);
return result;
} catch(e) {
ServerActions.connectionError(e);
}
},
sendPasswordCode: function(email) {
return new Promise(function(){
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/forgetpw.php?e=' + email,
type: 'GET',
dataType: 'text',
success: function(result) {
ServerActions.forgotPasswordSuccess(result);
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
sendPasswordCode: async function(email) {
try {
ServerActions.startLoading();
let result = await request.get('php/forgetpw.php?e=' + email);
ServerActions.forgotPasswordSuccess(result);
} catch(e) {
ServerActions.connectionError(e);
}
},
sendUsername: function(email) {
return new Promise(function(){
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/forgetusername.php?e=' + email,
type: 'GET',
dataType: 'text',
success: function(result) {
ServerActions.forgotUsernameSuccess(result);
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
sendUsername: async function(email) {
try {
ServerActions.startLoading();
let url = 'php/forgetusername.php?e=' + email;
let result = await request.get(url);
ServerActions.forgotUsernameSuccess(result);
} catch(e) {
ServerActions.connectionError(e);
}
},
resendActivation: function(email) {
return new Promise(function(){
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/regmailagain.php?e=' + email,
type: 'GET',
dataType: 'text',
success: function(result) {
ServerActions.resendActivationSuccess(result);
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
resendActivation: async function(email) {
try {
ServerActions.startLoading();
let result = await request.get('php/regmailagain.php?e=' + email);
ServerActions.resendActivationSuccess(result);
} catch(e) {
ServerActions.connectionError(e);
}
},
login: function(username, password) {
ServerActions.startLoading();
return new Promise(function(){
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/login.php?u=' + username + '&p=' + password,
type: 'GET',
dataType: 'text',
success: function(result) {
ServerActions.receiveAccount(result, username);
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
login: async function(username, password) {
try {
ServerActions.startLoading();
let result = await request.get('php/login.php?u=' + username + '&p=' + password);
ServerActions.receiveAccount(result, username);
} catch(e) {
ServerActions.connectionError(e);
}
},
logout: function() {
// ServerActions.startLoading();
logout: async function() {
ServerActions.logoutSuccess();
// return new Promise(function(){
// jQuery.ajax(
// {
// url: 'http://cha5app.dsa-sh.de/php/logout.php?uid=' + AccountStore.getID(),
// type: 'GET',
// dataType: 'text',
// success: function(result) {
// ServerActions.logoutSuccess(result);
// },
// error: function(error) {
// ServerActions.connectionError(error);
// }
// }
// );
// });
// try {
// ServerActions.startLoading();
// let result = await request.get('php/logout.php?uid=' + AccountStore.getID());
// ServerActions.logoutSuccess(result);
// } catch(e) {
// ServerActions.connectionError(e);
// }
},
logoutSync: function() {
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/logout.php?uid=' + AccountStore.getID(),
type: 'GET',
dataType: 'text',
async: false
}
);
setNewUsername: async function(name) {
try {
ServerActions.startLoading();
let userID = AccountStore.getID();
let url = 'php/changeaccount.php?uid=' + userID + '&src=username&v=' + name;
let result = await request.get(url);
ServerActions.changeUsernameSuccess(result, name);
} catch(e) {
ServerActions.connectionError(e);
}
},
setNewUsername: function(name) {
ServerActions.startLoading();
return new Promise(function(){
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/php.php?uid=' + AccountStore.getID() + '&src=username&v=' + name,
type: 'GET',
dataType: 'text',
success: function(result) {
ServerActions.changeUsernameSuccess(result, name);
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
setNewPassword: async function(password) {
try {
ServerActions.startLoading();
let userID = AccountStore.getID();
let url = 'php/changeaccount.php?uid=' + userID + '&src=password&v=' + password;
let result = await request.get(url);
ServerActions.changePasswordSuccess(result);
} catch(e) {
ServerActions.connectionError(e);
}
},
setNewPassword: function(password) {
ServerActions.startLoading();
return new Promise(function(){
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/php.php?uid=' + AccountStore.getID() + '&src=password&v=' + password,
type: 'GET',
dataType: 'text',
success: function(result) {
ServerActions.changePasswordSuccess(result);
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
deleteAccount: async function() {
try {
ServerActions.startLoading();
let result = await request.get('php/deleteaccount.php?uid=' + AccountStore.getID());
ServerActions.deleteAccountSuccess(result);
} catch(e) {
ServerActions.connectionError(e);
}
},
deleteAccount: function() {
ServerActions.startLoading();
return new Promise(function(){
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/deleteaccount.php?uid=' + AccountStore.getID(),
type: 'GET',
dataType: 'text',
success: function(result) {
ServerActions.deleteAccountSuccess(result);
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
getHeroes: async function() {
try {
ServerActions.startLoading();
let result = await request.get('php/getherolist.php?uid=' + AccountStore.getID());
ServerActions.herolistRefreshSuccess(result);
} catch(e) {
ServerActions.connectionError(e);
}
},
getHeroes: function(userid) {
ServerActions.startLoading();
return new Promise(function(){
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/getherolist.php?uid=' + (typeof userid === 'undefined' ? AccountStore.getID(): userid),
type: 'GET',
dataType: 'text',
success: function(result) {
ServerActions.herolistRefreshSuccess(result);
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
loadHero: async function(id) {
try {
ServerActions.startLoading();
ServerActions.loadHeroSuccess(id, `{
"sex":"m",
"pers":{
"_family": "ibn Rashtul",
"_placeofbirth": "Rashdul",
"_dateofbirth": "10. Boron 1001 BF",
"_age": "6",
"_haircolor": 2,
"_eyecolor": 3,
"_size": 167,
"_weight": 71,
"_title": "al'Eshta",
"_socialstatus": 2,
"_characteristics": "Reibt sich die Hände",
"_otherinfo": "Hat einen Golem ..."
},
"attr":{
"values":[
["ATTR_1",12,0],
["ATTR_2",13,0],
["ATTR_3",12,0],
["ATTR_4",13,0],
["ATTR_5",14,1],
["ATTR_6",13,0],
["ATTR_7",12,0],
["ATTR_8",11,0]
],
"_le":5,
"_le_add":0,
"_ae_add":0,
"_ke_add":0,
"_sk":-5,
"_zk":-5,
"_gs":8
},
"disadv":{
"active":[
["ADV_3",{}],["ADV_5",{}],["ADV_40",{}],["ADV_47",{"sid":"CT_2"}],["ADV_49",{}],["ADV_50",{}],["DISADV_1",[[2,2]]],["DISADV_15",{}],["DISADV_25",{}],["DISADV_40",{"tier":1}]
],
"_showRating":true
},
"talents":{
"active":[["TAL_8",6],["TAL_10",4],["TAL_18",7],["TAL_20",5],["TAL_21",4],["TAL_25",4],["TAL_28",9],["TAL_29",7],["TAL_34",4],["TAL_38",5],["TAL_39",3],["TAL_40",2],["TAL_47",5],["TAL_48",8],["TAL_50",7],["TAL_51",1],["TAL_55",1],["TAL_59",1]],
"_talentRating":true},
"ct":{
"active":[["CT_3",8],["CT_5",8]]
},
"spells":{
"active":[]
},
"chants":{
"active":[]
},
"sa":{
"active":[["SA_10",[["TAL_48","Test"]]],["SA_28",[9,14]],["SA_30",[[8,4],[23,2],[6,1]]],["SA_86",{"sid":1}]]
},
"history": []
}`);
// let result = await request.get('php/gethero.php?hid=' + id);
// ServerActions.loadHeroSuccess(id, result);
} catch(e) {
ServerActions.connectionError(e);
}
},
loadHero: function(id) {
ServerActions.startLoading();
ServerActions.loadHeroSuccess(id, `{
"sex":"m",
"pers":{
"_family": "ibn Rashtul",
"_placeofbirth": "Rashdul",
"_dateofbirth": "10. Boron 1001 BF",
"_age": "6",
"_haircolor": 2,
"_eyecolor": 3,
"_size": 167,
"_weight": 71,
"_title": "al'Eshta",
"_socialstatus": 2,
"_characteristics": "Reibt sich die Hände",
"_otherinfo": "Hat einen Golem ..."
},
"attr":{
"values":[
["ATTR_1",12,0],
["ATTR_2",13,0],
["ATTR_3",12,0],
["ATTR_4",13,0],
["ATTR_5",14,1],
["ATTR_6",13,0],
["ATTR_7",12,0],
["ATTR_8",11,0]
],
"_le":5,
"_le_add":0,
"_ae_add":0,
"_ke_add":0,
"_sk":-5,
"_zk":-5,
"_gs":8
},
"disadv":{
"active":[
["ADV_3",{}],["ADV_5",{}],["ADV_40",{}],["ADV_47",{"sid":"CT_2"}],["ADV_49",{}],["ADV_50",{}],["DISADV_1",[[2,2]]],["DISADV_15",{}],["DISADV_25",{}],["DISADV_40",{"tier":1}]
],
"_showRating":true
},
"talents":{
"active":[["TAL_8",6],["TAL_10",4],["TAL_18",7],["TAL_20",5],["TAL_21",4],["TAL_25",4],["TAL_28",9],["TAL_29",7],["TAL_34",4],["TAL_38",5],["TAL_39",3],["TAL_40",2],["TAL_47",5],["TAL_48",8],["TAL_50",7],["TAL_51",1],["TAL_55",1],["TAL_59",1]],
"_talentRating":true},
"ct":{
"active":[["CT_3",8],["CT_5",8]]
},
"spells":{
"active":[]
},
"chants":{
"active":[]
},
"sa":{
"active":[["SA_10",[["TAL_48","Test"]]],["SA_28",[9,14]],["SA_30",[[8,4],[23,2],[6,1]]],["SA_86",{"sid":1}]]
},
"history": []
}`);
// return new Promise(function(){
// jQuery.ajax(
// {
// url: 'http://cha5app.dsa-sh.de/php/gethero.php?hid=' + id,
// type: 'GET',
// dataType: 'text',
// success: function(result) {
// ServerActions.loadHeroSuccess(id, result);
// },
// error: function(error) {
// ServerActions.connectionError(error);
// }
// }
// );
// });
createNewHero: async function(heroname) {
try {
ServerActions.startLoading();
let url = 'php/newhero.php?uid=' + AccountStore.getID() + '&n=' + heroname;
let result = await request.get(url);
ServerActions.createNewHeroSuccess(result);
} catch(e) {
ServerActions.connectionError(e);
}
},
createNewHero: function(heroname) {
return new Promise(function(resolve){
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/newhero.php?uid=' + AccountStore.getID() + '&n=' + heroname,
type: 'GET',
dataType: 'text',
success: function(result) {
resolve(result);
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
},
saveHero: function(data) {
saveHero: async function(data) {
// try {
// ServerActions.startLoading();
// let url = 'php/save.php?short=' + data[0] + '&full=' + data[1];
// let result = await request.get(url);
// ServerActions.saveHeroSuccess(result);
// } catch(e) {
// ServerActions.connectionError(e);
// }
ServerActions.startLoading();
var blob = new Blob([data], { type: "application/json" });
var url = window.URL.createObjectURL(blob);
window.open(url);
// window.open('data:application/json;' + json);
// var w = window.open();
// w.document.open();
// w.document.write('<html><body><pre>' + json + '</pre></body></html>');
// w.document.close();
// return new Promise(function(){
// jQuery.ajax(
// {
// url: 'http://cha5app.dsa-sh.de/php/save.php?short=' + data[0] + '&full=' + data[1],
// type: 'POST',
// dataType: 'json',
// success: function() {
ServerActions.saveHeroSuccess();
// },
// error: function(error) {
// ServerActions.connectionError(error);
// }
// }
// );
// });
},
changeHeroAvatar: function(type, data) {
ServerActions.startLoading();
var urlAdd = '';
var finalData;
if (type === 'ext') {
urlAdd = '&url=' + data;
} else if (type === 'file') {
finalData = new FormData(data);
changeHeroAvatar: async function(type, data) {
try {
ServerActions.startLoading();
var urlAdd = '';
var finalData;
if (type === 'ext') {
urlAdd = '&url=' + data;
} else if (type === 'file') {
finalData = new FormData(data);
}
let url = 'php/uploadheropic.php?hid=' + ProfileStore.getID() + '&type=' + type + urlAdd;
let result = await request.post(url, finalData);
ServerActions.changeHeroAvatarSuccess(type === 'file' ? result : data);
} catch(e) {
ServerActions.connectionError(e);
}
return new Promise(function(){
jQuery.ajax({
url: 'http://cha5app.dsa-sh.de/php/uploadheropic.php?hid=' + ProfileStore.getID() + '&type=' + type + urlAdd,
type: 'POST',
data: finalData,
success: function(result) {
ServerActions.changeHeroAvatarSuccess(type === 'file' ? result : data);
},
error: function(error) {
ServerActions.connectionError(error);
}
});
});
},
deleteHero: function(heroid) {
ServerActions.startLoading();
return new Promise(function(resolve){
jQuery.ajax(
{
url: 'http://cha5app.dsa-sh.de/php/deletehero.php?uid=' + AccountStore.getID() + '&hid=' + heroid,
type: 'GET',
dataType: 'text',
success: function(result) {
resolve(result);
},
error: function(error) {
ServerActions.connectionError(error);
}
}
);
});
deleteHero: async function(heroid) {
try {
ServerActions.startLoading();
let url = 'php/deletehero.php?uid=' + AccountStore.getID() + '&hid=' + heroid;
let result = await request.get(url);
ServerActions.deleteHeroSuccess(result);
} catch(e) {
ServerActions.connectionError(e);
}
}
};
-11
View File
@@ -1,11 +0,0 @@
import { getAC, getIC } from '../ic.js';
it('returns 45 ap cost for SR 16 IC 5', () => {
const ap = getIC(16, 5);
expect(ap).toBe(45);
});
it('returns 4 ap cost for activating IC 4', () => {
const ap = getAC(4);
expect(ap).toBe(4);
});
+13
View File
@@ -0,0 +1,13 @@
import { getAC, getIC } from '../iccalc';
describe('iccalc', () => {
it('returns 45 ap cost for SR 16 IC 5', () => {
const ap = getIC(5, 16);
expect(ap).toBe(45);
});
it('returns 4 ap cost for activating IC 4', () => {
const ap = getAC(4);
expect(ap).toBe(4);
});
});
-15
View File
@@ -1,15 +0,0 @@
// AC = Activation Cost
// IC = Improvement Cost
export function getAC(ic) {
return ic === 5 ? 15 : ic;
}
export function getIC(sr, ic) {
const f = ic === 5 ? 15 : ic;
if (sr < 12 || (ic === 5 && sr < 14)) {
return f;
} else {
return (sr - (ic === 5 ? 13 : 11)) * f;
}
}
+17
View File
@@ -0,0 +1,17 @@
// AC = Activation Cost
// IC = Improvement Cost
export function getAC(ic) {
return ic === 5 ? 15 : ic;
}
export function getIC(ic, sr) {
const f = ic === 5 ? 15 : ic;
if (sr < 12 || (ic === 5 && sr < 14)) {
return f;
} else {
return (sr - (ic === 5 ? 13 : 11)) * f;
}
}
export default { getAC, getIC };
+31
View File
@@ -0,0 +1,31 @@
import jQuery from 'jQuery';
export function get(path, dataType = 'text') {
return new Promise((resolve, reject) => {
jQuery.ajax(
{
type: 'GET',
url: path,
dataType,
success: result => resolve(result),
error: error => reject(error)
}
);
});
}
export function post(path, data) {
return new Promise((resolve, reject) => {
jQuery.ajax(
{
type: 'POST',
url: path,
data,
success: result => resolve(result),
error: error => reject(error)
}
);
});
}
export default { get, post };
+37 -37
View File
@@ -1,55 +1,55 @@
import APStore from '../stores/APStore';
import AttributeStore from '../stores/AttributeStore';
import CombatTechniquesStore from '../stores/CombatTechniquesStore';
import CultureStore from '../stores/rcp/CultureStore';
import CultureStore from '../stores/CultureStore';
import DisAdvStore from '../stores/DisAdvStore';
import ELStore from '../stores/ELStore';
import HistoryStore from '../stores/HistoryStore';
import LiturgiesStore from '../stores/LiturgiesStore';
import PhaseStore from '../stores/PhaseStore';
import ProfessionStore from '../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../stores/rcp/ProfessionVariantStore';
import ProfessionStore from '../stores/ProfessionStore';
import ProfessionVariantStore from '../stores/ProfessionVariantStore';
import ProfileStore from '../stores/ProfileStore';
import RaceStore from '../stores/rcp/RaceStore';
import RaceStore from '../stores/RaceStore';
import SpecialAbilitiesStore from '../stores/SpecialAbilitiesStore';
import SpellsStore from '../stores/SpellsStore';
import TalentsStore from '../stores/TalentsStore';
import VersionStore from '../stores/core/VersionStore';
import VersionStore from '../stores/VersionStore';
import WebAPIUtils from './WebAPIUtils';
export default () => {
var data = [
{
client_version: VersionStore.get(),
date: (new Date()).toJSON(),
id: ProfileStore.getID(),
phase: PhaseStore.get(),
name: ProfileStore.getName(),
avatar: ProfileStore.getAvatar(),
ap: APStore.getForSave(),
el: ELStore.getStartID(),
r: RaceStore.getCurrentID(),
c: CultureStore.getCurrentID(),
p: ProfessionStore.getCurrentID(),
pv: ProfessionVariantStore.getCurrentID()
},
{
sex: ProfileStore.getSex(),
pers: ProfileStore.getAppearance(),
attr: AttributeStore.getForSave(),
disadv: DisAdvStore.getForSave(),
talents: TalentsStore.getForSave(),
ct: CombatTechniquesStore.getForSave(),
spells: SpellsStore.getForSave(),
chants: LiturgiesStore.getForSave(),
sa: SpecialAbilitiesStore.getForSave(),
eq: {},
items: {},
history: HistoryStore.getAll()
}
];
export const generateArray = () => [
{
client_version: VersionStore.get(),
date: (new Date()).toJSON(),
id: ProfileStore.getID(),
phase: PhaseStore.get(),
name: ProfileStore.getName(),
avatar: ProfileStore.getAvatar(),
ap: APStore.getForSave(),
el: ELStore.getStartID(),
r: RaceStore.getCurrentID(),
c: CultureStore.getCurrentID(),
p: ProfessionStore.getCurrentID(),
pv: ProfessionVariantStore.getCurrentID()
},
{
sex: ProfileStore.getSex(),
pers: ProfileStore.getAppearance(),
attr: AttributeStore.getForSave(),
disadv: DisAdvStore.getForSave(),
talents: TalentsStore.getForSave(),
ct: CombatTechniquesStore.getForSave(),
spells: SpellsStore.getForSave(),
chants: LiturgiesStore.getForSave(),
sa: SpecialAbilitiesStore.getForSave(),
eq: {},
items: {},
history: HistoryStore.getAll()
}
];
var json = JSON.stringify(data);
export default () => {
var json = JSON.stringify(generateArray());
WebAPIUtils.saveHero(json);
+3 -3
View File
@@ -1,6 +1,6 @@
import CultureStore from '../stores/rcp/CultureStore';
import ProfessionStore from '../stores/rcp/ProfessionStore';
import RaceStore from '../stores/rcp/RaceStore';
import CultureStore from '../stores/CultureStore';
import ProfessionStore from '../stores/ProfessionStore';
import RaceStore from '../stores/RaceStore';
import ListStore from '../stores/ListStore';
export const fn = (req, id) => {
+1 -1
View File
@@ -11,7 +11,7 @@ $ npm install babel-core
## Usage
```js
import babel from 'babel-core';
import * as babel from 'babel-core';
const code = `class Example {}`;
const result = babel.transform(code, { /* options */ });
+26 -40
View File
@@ -1,123 +1,123 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
exports.transformFileSync = exports.transformFile = exports.transformFromAst = exports.transform = exports.analyse = exports.Pipeline = exports.Plugin = exports.OptionManager = exports.traverse = exports.types = exports.messages = exports.util = exports.version = exports.template = exports.buildExternalHelpers = exports.options = exports.File = undefined;
var /*istanbul ignore next*/_node = require("./node");
var _node = require("./node");
/*istanbul ignore next*/Object.defineProperty(exports, "File", {
Object.defineProperty(exports, "File", {
enumerable: true,
get: function get() {
return _node.File;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "options", {
Object.defineProperty(exports, "options", {
enumerable: true,
get: function get() {
return _node.options;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "buildExternalHelpers", {
Object.defineProperty(exports, "buildExternalHelpers", {
enumerable: true,
get: function get() {
return _node.buildExternalHelpers;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "template", {
Object.defineProperty(exports, "template", {
enumerable: true,
get: function get() {
return _node.template;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "version", {
Object.defineProperty(exports, "version", {
enumerable: true,
get: function get() {
return _node.version;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "util", {
Object.defineProperty(exports, "util", {
enumerable: true,
get: function get() {
return _node.util;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "messages", {
Object.defineProperty(exports, "messages", {
enumerable: true,
get: function get() {
return _node.messages;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "types", {
Object.defineProperty(exports, "types", {
enumerable: true,
get: function get() {
return _node.types;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "traverse", {
Object.defineProperty(exports, "traverse", {
enumerable: true,
get: function get() {
return _node.traverse;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "OptionManager", {
Object.defineProperty(exports, "OptionManager", {
enumerable: true,
get: function get() {
return _node.OptionManager;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "Plugin", {
Object.defineProperty(exports, "Plugin", {
enumerable: true,
get: function get() {
return _node.Plugin;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "Pipeline", {
Object.defineProperty(exports, "Pipeline", {
enumerable: true,
get: function get() {
return _node.Pipeline;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "analyse", {
Object.defineProperty(exports, "analyse", {
enumerable: true,
get: function get() {
return _node.analyse;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "transform", {
Object.defineProperty(exports, "transform", {
enumerable: true,
get: function get() {
return _node.transform;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "transformFromAst", {
Object.defineProperty(exports, "transformFromAst", {
enumerable: true,
get: function get() {
return _node.transformFromAst;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "transformFile", {
Object.defineProperty(exports, "transformFile", {
enumerable: true,
get: function get() {
return _node.transformFile;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "transformFileSync", {
Object.defineProperty(exports, "transformFileSync", {
enumerable: true,
get: function get() {
return _node.transformFileSync;
}
});
/*istanbul ignore next*/exports.run = run;
/*istanbul ignore next*/exports.load = load;
exports.run = run;
exports.load = load;
function run(code) {
/*istanbul ignore next*/var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return new Function( /*istanbul ignore next*/(0, _node.transform)(code, opts).code)();
return new Function((0, _node.transform)(code, opts).code)();
}
function load(url, callback) {
/*istanbul ignore next*/var opts = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
/*istanbul ignore next*/var hold = arguments[3];
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var hold = arguments[3];
opts.filename = opts.filename || url;
@@ -134,7 +134,7 @@ function load(url, callback) {
if (!hold) run(param);
if (callback) callback(param);
} else {
throw new Error( /*istanbul ignore next*/"Could not load " + url);
throw new Error("Could not load " + url);
}
};
@@ -146,10 +146,6 @@ function runScripts() {
var types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
var index = 0;
/**
* Transform and execute script. Ensures correct load order.
*/
function exec() {
var param = scripts[index];
if (param instanceof Array) {
@@ -159,10 +155,6 @@ function runScripts() {
}
}
/**
* Load, transform, and execute all scripts.
*/
function run(script, i) {
var opts = {};
@@ -177,8 +169,6 @@ function runScripts() {
}
}
// Collect scripts with Babel `types`.
var _scripts = global.document.getElementsByTagName("script");
for (var i = 0; i < _scripts.length; ++i) {
@@ -193,10 +183,6 @@ function runScripts() {
exec();
}
/**
* Register load event to transform and execute scripts.
*/
if (global.addEventListener) {
global.addEventListener("DOMContentLoaded", runScripts, false);
} else if (global.attachEvent) {
+31 -45
View File
@@ -1,4 +1,4 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
exports.transformFromAst = exports.transform = exports.analyse = exports.Pipeline = exports.OptionManager = exports.traverse = exports.types = exports.messages = exports.util = exports.version = exports.template = exports.buildExternalHelpers = exports.options = exports.File = undefined;
@@ -11,7 +11,7 @@ Object.defineProperty(exports, "File", {
return _interopRequireDefault(_file).default;
}
});
/*istanbul ignore next*/
var _config = require("../transformation/file/options/config");
Object.defineProperty(exports, "options", {
@@ -20,7 +20,7 @@ Object.defineProperty(exports, "options", {
return _interopRequireDefault(_config).default;
}
});
/*istanbul ignore next*/
var _buildExternalHelpers = require("../tools/build-external-helpers");
Object.defineProperty(exports, "buildExternalHelpers", {
@@ -29,7 +29,7 @@ Object.defineProperty(exports, "buildExternalHelpers", {
return _interopRequireDefault(_buildExternalHelpers).default;
}
});
/*istanbul ignore next*/
var _babelTemplate = require("babel-template");
Object.defineProperty(exports, "template", {
@@ -38,7 +38,7 @@ Object.defineProperty(exports, "template", {
return _interopRequireDefault(_babelTemplate).default;
}
});
/*istanbul ignore next*/
var _package = require("../../package");
Object.defineProperty(exports, "version", {
@@ -47,87 +47,73 @@ Object.defineProperty(exports, "version", {
return _package.version;
}
});
/*istanbul ignore next*/exports.Plugin = Plugin;
/*istanbul ignore next*/exports.transformFile = transformFile;
/*istanbul ignore next*/exports.transformFileSync = transformFileSync;
exports.Plugin = Plugin;
exports.transformFile = transformFile;
exports.transformFileSync = transformFileSync;
var /*istanbul ignore next*/_isFunction = require("lodash/lang/isFunction");
var _isFunction = require("lodash/isFunction");
/*istanbul ignore next*/
var _isFunction2 = _interopRequireDefault(_isFunction);
var /*istanbul ignore next*/_fs = require("fs");
var _fs = require("fs");
/*istanbul ignore next*/
var _fs2 = _interopRequireDefault(_fs);
var /*istanbul ignore next*/_util = require("../util");
var _util = require("../util");
/*istanbul ignore next*/
var util = _interopRequireWildcard(_util);
var /*istanbul ignore next*/_babelMessages = require("babel-messages");
var _babelMessages = require("babel-messages");
/*istanbul ignore next*/
var messages = _interopRequireWildcard(_babelMessages);
var /*istanbul ignore next*/_babelTypes = require("babel-types");
var _babelTypes = require("babel-types");
/*istanbul ignore next*/
var t = _interopRequireWildcard(_babelTypes);
var /*istanbul ignore next*/_babelTraverse = require("babel-traverse");
var _babelTraverse = require("babel-traverse");
/*istanbul ignore next*/
var _babelTraverse2 = _interopRequireDefault(_babelTraverse);
var /*istanbul ignore next*/_optionManager = require("../transformation/file/options/option-manager");
var _optionManager = require("../transformation/file/options/option-manager");
/*istanbul ignore next*/
var _optionManager2 = _interopRequireDefault(_optionManager);
var /*istanbul ignore next*/_pipeline = require("../transformation/pipeline");
var _pipeline = require("../transformation/pipeline");
/*istanbul ignore next*/
var _pipeline2 = _interopRequireDefault(_pipeline);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//
exports.util = util;
/*istanbul ignore next*/exports.messages = messages;
/*istanbul ignore next*/exports.types = t;
/*istanbul ignore next*/exports.traverse = _babelTraverse2.default;
/*istanbul ignore next*/exports.OptionManager = _optionManager2.default;
exports.messages = messages;
exports.types = t;
exports.traverse = _babelTraverse2.default;
exports.OptionManager = _optionManager2.default;
function Plugin(alias) {
throw new Error( /*istanbul ignore next*/"The (" + alias + ") Babel 5 plugin is being run with Babel 6.");
throw new Error("The (" + alias + ") Babel 5 plugin is being run with Babel 6.");
}
//
/*istanbul ignore next*/exports.Pipeline = _pipeline2.default;
exports.Pipeline = _pipeline2.default;
var pipeline = new /*istanbul ignore next*/_pipeline2.default();
var analyse = /*istanbul ignore next*/exports.analyse = pipeline.analyse.bind(pipeline);
var transform = /*istanbul ignore next*/exports.transform = pipeline.transform.bind(pipeline);
var transformFromAst = /*istanbul ignore next*/exports.transformFromAst = pipeline.transformFromAst.bind(pipeline);
//
var pipeline = new _pipeline2.default();
var analyse = exports.analyse = pipeline.analyse.bind(pipeline);
var transform = exports.transform = pipeline.transform.bind(pipeline);
var transformFromAst = exports.transformFromAst = pipeline.transformFromAst.bind(pipeline);
function transformFile(filename, opts, callback) {
if ( /*istanbul ignore next*/(0, _isFunction2.default)(opts)) {
if ((0, _isFunction2.default)(opts)) {
callback = opts;
opts = {};
}
opts.filename = filename;
/*istanbul ignore next*/_fs2.default.readFile(filename, function (err, code) {
var result = /*istanbul ignore next*/void 0;
_fs2.default.readFile(filename, function (err, code) {
var result = void 0;
if (!err) {
try {
@@ -146,8 +132,8 @@ function transformFile(filename, opts, callback) {
}
function transformFileSync(filename) {
/*istanbul ignore next*/var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
opts.filename = filename;
return transform( /*istanbul ignore next*/_fs2.default.readFileSync(filename, "utf8"), opts);
return transform(_fs2.default.readFileSync(filename, "utf8"), opts);
}
+24 -27
View File
@@ -1,4 +1,4 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
@@ -9,40 +9,37 @@ var _getIterator3 = _interopRequireDefault(_getIterator2);
exports.default = function (dest, src) {
if (!dest || !src) return;
return (/*istanbul ignore next*/(0, _merge2.default)(dest, src, function (a, b) {
if (b && Array.isArray(a)) {
var newArray = b.slice(0);
return (0, _mergeWith2.default)(dest, src, function (a, b) {
if (b && Array.isArray(a)) {
var newArray = b.slice(0);
for ( /*istanbul ignore next*/var _iterator = a, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
/*istanbul ignore next*/
var _ref;
for (var _iterator = a, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var item = _ref;
if (newArray.indexOf(item) < 0) {
newArray.push(item);
}
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
return newArray;
var item = _ref;
if (newArray.indexOf(item) < 0) {
newArray.push(item);
}
}
})
);
return newArray;
}
});
};
var /*istanbul ignore next*/_merge = require("lodash/object/merge");
var _mergeWith = require("lodash/mergeWith");
/*istanbul ignore next*/
var _merge2 = _interopRequireDefault(_merge);
var _mergeWith2 = _interopRequireDefault(_mergeWith);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+3 -11
View File
@@ -1,4 +1,4 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
@@ -14,18 +14,10 @@ exports.default = function (ast, comments, tokens) {
throw new Error("Not a valid ast?");
};
var /*istanbul ignore next*/_babelTypes = require("babel-types");
var _babelTypes = require("babel-types");
/*istanbul ignore next*/
var t = _interopRequireWildcard(_babelTypes);
/*istanbul ignore next*/
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
module.exports = exports["default"];
/**
* Normalize an AST.
*
* - Wrap `Program` node with a `File` node.
*/
module.exports = exports["default"];
+10 -20
View File
@@ -1,4 +1,4 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
@@ -7,50 +7,40 @@ var _typeof2 = require("babel-runtime/helpers/typeof");
var _typeof3 = _interopRequireDefault(_typeof2);
exports.default = function (loc) {
/*istanbul ignore next*/var relative = arguments.length <= 1 || arguments[1] === undefined ? process.cwd() : arguments[1];
var relative = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : process.cwd();
// we're in the browser, probably
if ( /*istanbul ignore next*/(typeof _module2.default === "undefined" ? "undefined" : (0, _typeof3.default)(_module2.default)) === "object") return null;
if ((typeof _module2.default === "undefined" ? "undefined" : (0, _typeof3.default)(_module2.default)) === "object") return null;
var relativeMod = relativeModules[relative];
if (!relativeMod) {
relativeMod = new /*istanbul ignore next*/_module2.default();
relativeMod = new _module2.default();
// We need to define an id and filename on our "fake" relative` module so that
// Node knows what "." means in the case of us trying to resolve a plugin
// such as "./myPlugins/somePlugin.js". If we don't specify id and filename here,
// Node presumes "." is process.cwd(), not our relative path.
// Since this fake module is never "loaded", we don't have to worry about mutating
// any global Node module cache state here.
var filename = /*istanbul ignore next*/_path2.default.join(relative, ".babelrc");
var filename = _path2.default.join(relative, ".babelrc");
relativeMod.id = filename;
relativeMod.filename = filename;
relativeMod.paths = /*istanbul ignore next*/_module2.default._nodeModulePaths(relative);
relativeMod.paths = _module2.default._nodeModulePaths(relative);
relativeModules[relative] = relativeMod;
}
try {
return (/*istanbul ignore next*/_module2.default._resolveFilename(loc, relativeMod)
);
return _module2.default._resolveFilename(loc, relativeMod);
} catch (err) {
return null;
}
};
var /*istanbul ignore next*/_module = require("module");
var _module = require("module");
/*istanbul ignore next*/
var _module2 = _interopRequireDefault(_module);
var /*istanbul ignore next*/_path = require("path");
var _path = require("path");
/*istanbul ignore next*/
var _path2 = _interopRequireDefault(_path);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var relativeModules = {};
/*istanbul ignore next*/module.exports = exports["default"];
module.exports = exports["default"];
+9 -10
View File
@@ -1,4 +1,4 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
@@ -23,13 +23,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
var Store = function (_Map) {
(0, _inherits3.default)(Store, _Map);
function /*istanbul ignore next*/Store() {
/*istanbul ignore next*/(0, _classCallCheck3.default)(this, Store);
function Store() {
(0, _classCallCheck3.default)(this, Store);
var _this = (0, _possibleConstructorReturn3.default)(this, /*istanbul ignore next*/_Map.call( /*istanbul ignore next*/this));
var _this = (0, _possibleConstructorReturn3.default)(this, _Map.call(this));
/*istanbul ignore next*/_this.dynamicData = {};
/*istanbul ignore next*/return _this;
_this.dynamicData = {};
return _this;
}
Store.prototype.setDynamic = function setDynamic(key, fn) {
@@ -38,8 +38,7 @@ var Store = function (_Map) {
Store.prototype.get = function get(key) {
if (this.has(key)) {
return (/*istanbul ignore next*/_Map.prototype.get. /*istanbul ignore next*/call( /*istanbul ignore next*/this, key)
);
return _Map.prototype.get.call(this, key);
} else {
if (Object.prototype.hasOwnProperty.call(this.dynamicData, key)) {
var val = this.dynamicData[key]();
@@ -52,5 +51,5 @@ var Store = function (_Map) {
return Store;
}(_map2.default);
/*istanbul ignore next*/exports.default = Store;
/*istanbul ignore next*/module.exports = exports["default"];
exports.default = Store;
module.exports = exports["default"];
+13 -23
View File
@@ -1,9 +1,9 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
exports.default = function (whitelist) {
/*istanbul ignore next*/var outputType = arguments.length <= 1 || arguments[1] === undefined ? "global" : arguments[1];
var outputType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "global";
var namespace = t.identifier("babelHelpers");
@@ -11,7 +11,7 @@ exports.default = function (whitelist) {
return buildHelpers(body, namespace, whitelist);
};
var tree = /*istanbul ignore next*/void 0;
var tree = void 0;
var build = {
global: buildGlobal,
@@ -25,48 +25,38 @@ exports.default = function (whitelist) {
throw new Error(messages.get("unsupportedOutputType", outputType));
}
return (/*istanbul ignore next*/(0, _babelGenerator2.default)(tree).code
);
return (0, _babelGenerator2.default)(tree).code;
};
var /*istanbul ignore next*/_babelHelpers = require("babel-helpers");
var _babelHelpers = require("babel-helpers");
/*istanbul ignore next*/
var helpers = _interopRequireWildcard(_babelHelpers);
var /*istanbul ignore next*/_babelGenerator = require("babel-generator");
var _babelGenerator = require("babel-generator");
/*istanbul ignore next*/
var _babelGenerator2 = _interopRequireDefault(_babelGenerator);
var /*istanbul ignore next*/_babelMessages = require("babel-messages");
var _babelMessages = require("babel-messages");
/*istanbul ignore next*/
var messages = _interopRequireWildcard(_babelMessages);
var /*istanbul ignore next*/_babelTemplate = require("babel-template");
var _babelTemplate = require("babel-template");
/*istanbul ignore next*/
var _babelTemplate2 = _interopRequireDefault(_babelTemplate);
var /*istanbul ignore next*/_each = require("lodash/collection/each");
var _each = require("lodash/each");
/*istanbul ignore next*/
var _each2 = _interopRequireDefault(_each);
var /*istanbul ignore next*/_babelTypes = require("babel-types");
var _babelTypes = require("babel-types");
/*istanbul ignore next*/
var t = _interopRequireWildcard(_babelTypes);
/*istanbul ignore next*/
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
/* eslint max-len: 0 */
var buildUmdWrapper = /*istanbul ignore next*/(0, _babelTemplate2.default)( /*istanbul ignore next*/"\n (function (root, factory) {\n if (typeof define === \"function\" && define.amd) {\n define(AMD_ARGUMENTS, factory);\n } else if (typeof exports === \"object\") {\n factory(COMMON_ARGUMENTS);\n } else {\n factory(BROWSER_ARGUMENTS);\n }\n })(UMD_ROOT, function (FACTORY_PARAMETERS) {\n FACTORY_BODY\n });\n");
var buildUmdWrapper = (0, _babelTemplate2.default)("\n (function (root, factory) {\n if (typeof define === \"function\" && define.amd) {\n define(AMD_ARGUMENTS, factory);\n } else if (typeof exports === \"object\") {\n factory(COMMON_ARGUMENTS);\n } else {\n factory(BROWSER_ARGUMENTS);\n }\n })(UMD_ROOT, function (FACTORY_PARAMETERS) {\n FACTORY_BODY\n });\n");
function buildGlobal(namespace, builder) {
var body = [];
@@ -105,11 +95,11 @@ function buildVar(namespace, builder) {
}
function buildHelpers(body, namespace, whitelist) {
/*istanbul ignore next*/(0, _each2.default)(helpers.list, function (name) {
(0, _each2.default)(helpers.list, function (name) {
if (whitelist && whitelist.indexOf(name) < 0) return;
var key = t.identifier(name);
body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(namespace, key), helpers.get(name))));
});
}
/*istanbul ignore next*/module.exports = exports["default"];
module.exports = exports["default"];
+149 -150
View File
@@ -1,4 +1,4 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
exports.File = undefined;
@@ -31,108 +31,89 @@ var _inherits2 = require("babel-runtime/helpers/inherits");
var _inherits3 = _interopRequireDefault(_inherits2);
var /*istanbul ignore next*/_babelHelpers = require("babel-helpers");
var _babelHelpers = require("babel-helpers");
/*istanbul ignore next*/
var _babelHelpers2 = _interopRequireDefault(_babelHelpers);
var /*istanbul ignore next*/_metadata = require("./metadata");
var _metadata = require("./metadata");
/*istanbul ignore next*/
var metadataVisitor = _interopRequireWildcard(_metadata);
var /*istanbul ignore next*/_convertSourceMap = require("convert-source-map");
var _convertSourceMap = require("convert-source-map");
/*istanbul ignore next*/
var _convertSourceMap2 = _interopRequireDefault(_convertSourceMap);
var /*istanbul ignore next*/_optionManager = require("./options/option-manager");
var _optionManager = require("./options/option-manager");
/*istanbul ignore next*/
var _optionManager2 = _interopRequireDefault(_optionManager);
var /*istanbul ignore next*/_pluginPass = require("../plugin-pass");
var _pluginPass = require("../plugin-pass");
/*istanbul ignore next*/
var _pluginPass2 = _interopRequireDefault(_pluginPass);
var /*istanbul ignore next*/_shebangRegex = require("shebang-regex");
var _babelTraverse = require("babel-traverse");
/*istanbul ignore next*/
var _shebangRegex2 = _interopRequireDefault(_shebangRegex);
var /*istanbul ignore next*/_babelTraverse = require("babel-traverse");
/*istanbul ignore next*/
var _babelTraverse2 = _interopRequireDefault(_babelTraverse);
var /*istanbul ignore next*/_sourceMap = require("source-map");
var _sourceMap = require("source-map");
/*istanbul ignore next*/
var _sourceMap2 = _interopRequireDefault(_sourceMap);
var /*istanbul ignore next*/_babelGenerator = require("babel-generator");
var _babelGenerator = require("babel-generator");
/*istanbul ignore next*/
var _babelGenerator2 = _interopRequireDefault(_babelGenerator);
var /*istanbul ignore next*/_babelCodeFrame = require("babel-code-frame");
var _babelCodeFrame = require("babel-code-frame");
/*istanbul ignore next*/
var _babelCodeFrame2 = _interopRequireDefault(_babelCodeFrame);
var /*istanbul ignore next*/_defaults = require("lodash/object/defaults");
var _defaults = require("lodash/defaults");
/*istanbul ignore next*/
var _defaults2 = _interopRequireDefault(_defaults);
var /*istanbul ignore next*/_logger = require("./logger");
var _logger = require("./logger");
/*istanbul ignore next*/
var _logger2 = _interopRequireDefault(_logger);
var /*istanbul ignore next*/_store = require("../../store");
var _store = require("../../store");
/*istanbul ignore next*/
var _store2 = _interopRequireDefault(_store);
var /*istanbul ignore next*/_babylon = require("babylon");
var _babylon = require("babylon");
var /*istanbul ignore next*/_util = require("../../util");
var _util = require("../../util");
/*istanbul ignore next*/
var util = _interopRequireWildcard(_util);
var /*istanbul ignore next*/_path = require("path");
var _path = require("path");
/*istanbul ignore next*/
var _path2 = _interopRequireDefault(_path);
var /*istanbul ignore next*/_babelTypes = require("babel-types");
var _babelTypes = require("babel-types");
/*istanbul ignore next*/
var t = _interopRequireWildcard(_babelTypes);
var /*istanbul ignore next*/_blockHoist = require("../internal-plugins/block-hoist");
var _resolve = require("../../helpers/resolve");
var _resolve2 = _interopRequireDefault(_resolve);
var _blockHoist = require("../internal-plugins/block-hoist");
/*istanbul ignore next*/
var _blockHoist2 = _interopRequireDefault(_blockHoist);
var /*istanbul ignore next*/_shadowFunctions = require("../internal-plugins/shadow-functions");
var _shadowFunctions = require("../internal-plugins/shadow-functions");
/*istanbul ignore next*/
var _shadowFunctions2 = _interopRequireDefault(_shadowFunctions);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* global BabelFileResult, BabelParserOptions, BabelFileMetadata */
/* eslint max-len: 0 */
var shebangRegex = /^#!.*/;
var INTERNAL_PLUGINS = [[/*istanbul ignore next*/_blockHoist2.default], [/*istanbul ignore next*/_shadowFunctions2.default]];
var INTERNAL_PLUGINS = [[_blockHoist2.default], [_shadowFunctions2.default]];
var errorVisitor = { /*istanbul ignore next*/
var errorVisitor = {
enter: function enter(path, state) {
var loc = path.node.loc;
if (loc) {
@@ -142,49 +123,42 @@ var errorVisitor = { /*istanbul ignore next*/
}
};
/*istanbul ignore next*/
var File = function (_Store) {
(0, _inherits3.default)(File, _Store);
function /*istanbul ignore next*/File() {
/*istanbul ignore next*/var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
/*istanbul ignore next*/var pipeline = arguments[1];
/*istanbul ignore next*/(0, _classCallCheck3.default)(this, File);
function File() {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var pipeline = arguments[1];
(0, _classCallCheck3.default)(this, File);
var _this = (0, _possibleConstructorReturn3.default)(this, /*istanbul ignore next*/_Store.call( /*istanbul ignore next*/this));
var _this = (0, _possibleConstructorReturn3.default)(this, _Store.call(this));
/*istanbul ignore next*/_this.pipeline = pipeline;
_this.pipeline = pipeline;
/*istanbul ignore next*/_this.log = new /*istanbul ignore next*/_logger2.default(_this, opts.filename || "unknown");
/*istanbul ignore next*/_this.opts = /*istanbul ignore next*/_this.initOptions(opts);
_this.log = new _logger2.default(_this, opts.filename || "unknown");
_this.opts = _this.initOptions(opts);
/*istanbul ignore next*/_this.parserOpts = {
highlightCode: /*istanbul ignore next*/_this.opts.highlightCode,
nonStandard: /*istanbul ignore next*/_this.opts.nonStandard,
sourceType: /*istanbul ignore next*/_this.opts.sourceType,
filename: /*istanbul ignore next*/_this.opts.filename,
_this.parserOpts = {
sourceType: _this.opts.sourceType,
sourceFileName: _this.opts.filename,
plugins: []
};
/*istanbul ignore next*/_this.pluginVisitors = [];
/*istanbul ignore next*/_this.pluginPasses = [];
_this.pluginVisitors = [];
_this.pluginPasses = [];
// Plugins for top-level options.
/*istanbul ignore next*/_this.buildPluginsForOptions( /*istanbul ignore next*/_this.opts);
_this.buildPluginsForOptions(_this.opts);
// If we are in the "pass per preset" mode, build
// also plugins for each preset.
if ( /*istanbul ignore next*/_this.opts.passPerPreset) {
// All the "per preset" options are inherited from the main options.
/*istanbul ignore next*/_this.perPresetOpts = [];
/*istanbul ignore next*/_this.opts.presets.forEach(function (presetOpts) {
var perPresetOpts = /*istanbul ignore next*/(0, _assign2.default)( /*istanbul ignore next*/(0, _create2.default)( /*istanbul ignore next*/_this.opts), presetOpts);
/*istanbul ignore next*/_this.perPresetOpts.push(perPresetOpts);
/*istanbul ignore next*/_this.buildPluginsForOptions(perPresetOpts);
if (_this.opts.passPerPreset) {
_this.perPresetOpts = [];
_this.opts.presets.forEach(function (presetOpts) {
var perPresetOpts = (0, _assign2.default)((0, _create2.default)(_this.opts), presetOpts);
_this.perPresetOpts.push(perPresetOpts);
_this.buildPluginsForOptions(perPresetOpts);
});
}
/*istanbul ignore next*/_this.metadata = {
_this.metadata = {
usedHelpers: [],
marked: [],
modules: {
@@ -196,26 +170,25 @@ var File = function (_Store) {
}
};
/*istanbul ignore next*/_this.dynamicImportTypes = {};
/*istanbul ignore next*/_this.dynamicImportIds = {};
/*istanbul ignore next*/_this.dynamicImports = [];
/*istanbul ignore next*/_this.declarations = {};
/*istanbul ignore next*/_this.usedHelpers = {};
_this.dynamicImportTypes = {};
_this.dynamicImportIds = {};
_this.dynamicImports = [];
_this.declarations = {};
_this.usedHelpers = {};
/*istanbul ignore next*/_this.path = null;
/*istanbul ignore next*/_this.ast = {};
_this.path = null;
_this.ast = {};
/*istanbul ignore next*/_this.code = "";
/*istanbul ignore next*/_this.shebang = "";
_this.code = "";
_this.shebang = "";
/*istanbul ignore next*/_this.hub = new /*istanbul ignore next*/_babelTraverse.Hub(_this);
/*istanbul ignore next*/return _this;
_this.hub = new _babelTraverse.Hub(_this);
return _this;
}
File.prototype.getMetadata = function getMetadata() {
var has = false;
for ( /*istanbul ignore next*/var _iterator = this.ast.program.body, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
/*istanbul ignore next*/
for (var _iterator = this.ast.program.body, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
@@ -240,7 +213,7 @@ var File = function (_Store) {
};
File.prototype.initOptions = function initOptions(opts) {
opts = new /*istanbul ignore next*/_optionManager2.default(this.log, this.pipeline).init(opts);
opts = new _optionManager2.default(this.log, this.pipeline).init(opts);
if (opts.inputSourceMap) {
opts.sourceMaps = true;
@@ -250,27 +223,27 @@ var File = function (_Store) {
opts.moduleIds = true;
}
opts.basename = /*istanbul ignore next*/_path2.default.basename(opts.filename, /*istanbul ignore next*/_path2.default.extname(opts.filename));
opts.basename = _path2.default.basename(opts.filename, _path2.default.extname(opts.filename));
opts.ignore = util.arrayify(opts.ignore, util.regexify);
if (opts.only) opts.only = util.arrayify(opts.only, util.regexify);
/*istanbul ignore next*/(0, _defaults2.default)(opts, {
(0, _defaults2.default)(opts, {
moduleRoot: opts.sourceRoot
});
/*istanbul ignore next*/(0, _defaults2.default)(opts, {
(0, _defaults2.default)(opts, {
sourceRoot: opts.moduleRoot
});
/*istanbul ignore next*/(0, _defaults2.default)(opts, {
(0, _defaults2.default)(opts, {
filenameRelative: opts.filename
});
var basenameRelative = /*istanbul ignore next*/_path2.default.basename(opts.filenameRelative);
var basenameRelative = _path2.default.basename(opts.filenameRelative);
/*istanbul ignore next*/(0, _defaults2.default)(opts, {
(0, _defaults2.default)(opts, {
sourceFileName: basenameRelative,
sourceMapTarget: basenameRelative
});
@@ -287,9 +260,7 @@ var File = function (_Store) {
var currentPluginVisitors = [];
var currentPluginPasses = [];
// init plugins!
for ( /*istanbul ignore next*/var _iterator2 = plugins, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
/*istanbul ignore next*/
for (var _iterator2 = plugins, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
var _ref2;
if (_isArray2) {
@@ -302,11 +273,12 @@ var File = function (_Store) {
}
var ref = _ref2;
/*istanbul ignore next*/var plugin = ref[0];
/*istanbul ignore next*/var pluginOpts = ref[1]; // todo: fix - can't embed in loop head because of flow bug
var plugin = ref[0];
var pluginOpts = ref[1];
currentPluginVisitors.push(plugin.visitor);
currentPluginPasses.push(new /*istanbul ignore next*/_pluginPass2.default(this, plugin, pluginOpts));
currentPluginPasses.push(new _pluginPass2.default(this, plugin, pluginOpts));
if (plugin.manipulateOptions) {
plugin.manipulateOptions(opts, this.parserOpts, this);
@@ -323,7 +295,6 @@ var File = function (_Store) {
return null;
}
// moduleId is n/a if a `getModuleId()` is provided
if (opts.moduleId != null && !opts.getModuleId) {
return opts.moduleId;
}
@@ -340,21 +311,17 @@ var File = function (_Store) {
}
if (opts.sourceRoot != null) {
// remove sourceRoot from filename
var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
}
// remove extension
filenameRelative = filenameRelative.replace(/\.(\w*?)$/, "");
moduleName += filenameRelative;
// normalize path separators
moduleName = moduleName.replace(/\\/g, "/");
if (opts.getModuleId) {
// If return is falsy, assume they want us to use our generated default name
return opts.getModuleId(moduleName) || moduleName;
} else {
return moduleName;
@@ -368,9 +335,9 @@ var File = function (_Store) {
};
File.prototype.addImport = function addImport(source, imported) {
/*istanbul ignore next*/var name = arguments.length <= 2 || arguments[2] === undefined ? imported : arguments[2];
var name = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : imported;
var alias = /*istanbul ignore next*/source + ":" + imported;
var alias = source + ":" + imported;
var id = this.dynamicImportIds[alias];
if (!id) {
@@ -414,7 +381,7 @@ var File = function (_Store) {
return t.memberExpression(runtime, t.identifier(name));
}
var ref = /*istanbul ignore next*/(0, _babelHelpers2.default)(name);
var ref = (0, _babelHelpers2.default)(name);
var uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
if (t.isFunctionExpression(ref) && !ref.id) {
@@ -436,12 +403,10 @@ var File = function (_Store) {
};
File.prototype.addTemplateObject = function addTemplateObject(helperName, strings, raw) {
// Generate a unique name based on the string literals so we dedupe
// identical strings used in the program.
var stringIds = raw.elements.map(function (string) {
return string.value;
});
var name = /*istanbul ignore next*/helperName + "_" + raw.elements.length + "_" + stringIds.join(",");
var name = helperName + "_" + raw.elements.length + "_" + stringIds.join(",");
var declar = this.declarations[name];
if (declar) return declar;
@@ -454,13 +419,12 @@ var File = function (_Store) {
this.scope.push({
id: uid,
init: init,
_blockHoist: 1.9 // This ensures that we don't fail if not using function expression helpers
});
_blockHoist: 1.9 });
return uid;
};
File.prototype.buildCodeFrameError = function buildCodeFrameError(node, msg) {
/*istanbul ignore next*/var Error = arguments.length <= 2 || arguments[2] === undefined ? SyntaxError : arguments[2];
var Error = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : SyntaxError;
var loc = node && (node.loc || node._loc);
@@ -469,7 +433,7 @@ var File = function (_Store) {
if (loc) {
err.loc = loc.start;
} else {
/*istanbul ignore next*/(0, _babelTraverse2.default)(node, errorVisitor, this.scope, err);
(0, _babelTraverse2.default)(node, errorVisitor, this.scope, err);
err.message += " (This is an error on an internal node. Probably an internal error";
@@ -487,18 +451,15 @@ var File = function (_Store) {
var inputMap = this.opts.inputSourceMap;
if (inputMap) {
/*istanbul ignore next*/
var _ret = function () {
var inputMapConsumer = new /*istanbul ignore next*/_sourceMap2.default.SourceMapConsumer(inputMap);
var outputMapConsumer = new /*istanbul ignore next*/_sourceMap2.default.SourceMapConsumer(map);
var inputMapConsumer = new _sourceMap2.default.SourceMapConsumer(inputMap);
var outputMapConsumer = new _sourceMap2.default.SourceMapConsumer(map);
var mergedGenerator = new /*istanbul ignore next*/_sourceMap2.default.SourceMapGenerator({
var mergedGenerator = new _sourceMap2.default.SourceMapGenerator({
file: inputMapConsumer.file,
sourceRoot: inputMapConsumer.sourceRoot
});
// This assumes the output map always has a single source, since Babel always compiles a single source file to a
// single output file.
var source = outputMapConsumer.sources[0];
inputMapConsumer.eachMapping(function (mapping) {
@@ -523,27 +484,53 @@ var File = function (_Store) {
var mergedMap = mergedGenerator.toJSON();
inputMap.mappings = mergedMap.mappings;
return (/*istanbul ignore next*/{
v: inputMap
}
);
return {
v: inputMap
};
}();
/*istanbul ignore next*/if ((typeof _ret === "undefined" ? "undefined" : (0, _typeof3.default)(_ret)) === "object") return _ret.v;
if ((typeof _ret === "undefined" ? "undefined" : (0, _typeof3.default)(_ret)) === "object") return _ret.v;
} else {
return map;
}
};
File.prototype.parse = function parse(code) {
var parseCode = _babylon.parse;
var parserOpts = this.opts.parserOpts;
if (parserOpts) {
parserOpts = (0, _assign2.default)({}, this.parserOpts, parserOpts);
if (parserOpts.parser) {
if (typeof parserOpts.parser === "string") {
var dirname = _path2.default.dirname(this.opts.filename) || process.cwd();
var parser = (0, _resolve2.default)(parserOpts.parser, dirname);
if (parser) {
parseCode = require(parser).parse;
} else {
throw new Error("Couldn't find parser " + parserOpts.parser + " with \"parse\" method relative to directory " + dirname);
}
} else {
parseCode = parserOpts.parser;
}
parserOpts.parser = {
parse: function parse(source) {
return (0, _babylon.parse)(source, parserOpts);
}
};
}
}
this.log.debug("Parse start");
var ast = /*istanbul ignore next*/(0, _babylon.parse)(code, this.parserOpts);
var ast = parseCode(code, parserOpts || this.parserOpts);
this.log.debug("Parse stop");
return ast;
};
File.prototype._addAst = function _addAst(ast) {
this.path = /*istanbul ignore next*/_babelTraverse.NodePath.get({
this.path = _babelTraverse.NodePath.get({
hub: this.hub,
parentPath: null,
parent: ast,
@@ -562,13 +549,14 @@ var File = function (_Store) {
};
File.prototype.transform = function transform() {
// In the "pass per preset" mode, we have grouped passes.
// Otherwise, there is only one plain pluginPasses array.
for (var i = 0; i < this.pluginPasses.length; i++) {
var pluginPasses = this.pluginPasses[i];
this.call("pre", pluginPasses);
this.log.debug("Start transform traverse");
/*istanbul ignore next*/(0, _babelTraverse2.default)(this.ast, /*istanbul ignore next*/_babelTraverse2.default.visitors.merge(this.pluginVisitors[i], pluginPasses), this.scope);
var visitor = _babelTraverse2.default.visitors.merge(this.pluginVisitors[i], pluginPasses, this.opts.wrapPluginVisitorMethod);
(0, _babelTraverse2.default)(this.ast, visitor, this.scope);
this.log.debug("End transform traverse");
this.call("post", pluginPasses);
}
@@ -592,17 +580,15 @@ var File = function (_Store) {
err._babel = true;
}
var message = err.message = /*istanbul ignore next*/this.opts.filename + ": " + err.message;
var message = err.message = this.opts.filename + ": " + err.message;
var loc = err.loc;
if (loc) {
err.codeFrame = /*istanbul ignore next*/(0, _babelCodeFrame2.default)(code, loc.line, loc.column + 1, this.opts);
err.codeFrame = (0, _babelCodeFrame2.default)(code, loc.line, loc.column + 1, this.opts);
message += "\n" + err.codeFrame;
}
if (process.browser) {
// chrome has it's own pretty stringifier which doesn't use the stack property
// https://github.com/babel/babel/issues/2175
err.message = message;
}
@@ -633,8 +619,7 @@ var File = function (_Store) {
};
File.prototype.call = function call(key, pluginPasses) {
for ( /*istanbul ignore next*/var _iterator3 = pluginPasses, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
/*istanbul ignore next*/
for (var _iterator3 = pluginPasses, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
var _ref3;
if (_isArray3) {
@@ -658,10 +643,10 @@ var File = function (_Store) {
var opts = this.opts;
if (opts.inputSourceMap !== false) {
var inputMap = /*istanbul ignore next*/_convertSourceMap2.default.fromSource(code);
var inputMap = _convertSourceMap2.default.fromSource(code);
if (inputMap) {
opts.inputSourceMap = inputMap.toObject();
code = /*istanbul ignore next*/_convertSourceMap2.default.removeComments(code);
code = _convertSourceMap2.default.removeComments(code);
}
}
@@ -669,18 +654,18 @@ var File = function (_Store) {
};
File.prototype.parseShebang = function parseShebang() {
var shebangMatch = /*istanbul ignore next*/_shebangRegex2.default.exec(this.code);
var shebangMatch = shebangRegex.exec(this.code);
if (shebangMatch) {
this.shebang = shebangMatch[0];
this.code = this.code.replace( /*istanbul ignore next*/_shebangRegex2.default, "");
this.code = this.code.replace(shebangRegex, "");
}
};
File.prototype.makeResult = function makeResult(_ref4) {
/*istanbul ignore next*/var code = _ref4.code;
/*istanbul ignore next*/var map = _ref4.map;
/*istanbul ignore next*/var ast = _ref4.ast;
/*istanbul ignore next*/var ignored = _ref4.ignored;
var code = _ref4.code;
var map = _ref4.map;
var ast = _ref4.ast;
var ignored = _ref4.ignored;
var result = {
metadata: null,
@@ -713,17 +698,31 @@ var File = function (_Store) {
var result = { ast: ast };
if (!opts.code) return this.makeResult(result);
var gen = _babelGenerator2.default;
if (opts.generatorOpts.generator) {
gen = opts.generatorOpts.generator;
if (typeof gen === "string") {
var dirname = _path2.default.dirname(this.opts.filename) || process.cwd();
var generator = (0, _resolve2.default)(gen, dirname);
if (generator) {
gen = require(generator).print;
} else {
throw new Error("Couldn't find generator " + gen + " with \"print\" method relative to directory " + dirname);
}
}
}
this.log.debug("Generation start");
var _result = /*istanbul ignore next*/(0, _babelGenerator2.default)(ast, opts, this.code);
var _result = gen(ast, opts.generatorOpts ? (0, _assign2.default)(opts, opts.generatorOpts) : opts, this.code);
result.code = _result.code;
result.map = _result.map;
this.log.debug("Generation end");
if (this.shebang) {
// add back shebang
result.code = /*istanbul ignore next*/this.shebang + "\n" + result.code;
result.code = this.shebang + "\n" + result.code;
}
if (result.map) {
@@ -731,7 +730,7 @@ var File = function (_Store) {
}
if (opts.sourceMaps === "inline" || opts.sourceMaps === "both") {
result.code += "\n" + /*istanbul ignore next*/_convertSourceMap2.default.fromObject(result.map).toComment();
result.code += "\n" + _convertSourceMap2.default.fromObject(result.map).toComment();
}
if (opts.sourceMaps === "inline") {
@@ -744,5 +743,5 @@ var File = function (_Store) {
return File;
}(_store2.default);
/*istanbul ignore next*/exports.default = File;
/*istanbul ignore next*/exports.File = File;
exports.default = File;
exports.File = File;
+11 -15
View File
@@ -1,4 +1,4 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
@@ -6,30 +6,28 @@ var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var /*istanbul ignore next*/_node = require("debug/node");
var _node = require("debug/node");
/*istanbul ignore next*/
var _node2 = _interopRequireDefault(_node);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var verboseDebug = /*istanbul ignore next*/(0, _node2.default)("babel:verbose");
var generalDebug = /*istanbul ignore next*/(0, _node2.default)("babel");
var verboseDebug = (0, _node2.default)("babel:verbose");
var generalDebug = (0, _node2.default)("babel");
var seenDeprecatedMessages = [];
/*istanbul ignore next*/
var Logger = function () {
function /*istanbul ignore next*/Logger(file, filename) {
/*istanbul ignore next*/(0, _classCallCheck3.default)(this, Logger);
function Logger(file, filename) {
(0, _classCallCheck3.default)(this, Logger);
this.filename = filename;
this.file = file;
}
Logger.prototype._buildMessage = function _buildMessage(msg) {
var parts = /*istanbul ignore next*/"[BABEL] " + this.filename;
if (msg) parts += /*istanbul ignore next*/": " + msg;
var parts = "[BABEL] " + this.filename;
if (msg) parts += ": " + msg;
return parts;
};
@@ -38,7 +36,7 @@ var Logger = function () {
};
Logger.prototype.error = function error(msg) {
/*istanbul ignore next*/var Constructor = arguments.length <= 1 || arguments[1] === undefined ? Error : arguments[1];
var Constructor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Error;
throw new Constructor(this._buildMessage(msg));
};
@@ -48,10 +46,8 @@ var Logger = function () {
msg = this._buildMessage(msg);
// already seen this message
if (seenDeprecatedMessages.indexOf(msg) >= 0) return;
// make sure we don't see it again
seenDeprecatedMessages.push(msg);
console.error(msg);
@@ -72,5 +68,5 @@ var Logger = function () {
return Logger;
}();
/*istanbul ignore next*/exports.default = Logger;
/*istanbul ignore next*/module.exports = exports["default"];
exports.default = Logger;
module.exports = exports["default"];
+10 -23
View File
@@ -1,4 +1,4 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
exports.ImportDeclaration = exports.ModuleDeclaration = undefined;
@@ -8,21 +8,19 @@ var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
exports.ExportDeclaration = ExportDeclaration;
/*istanbul ignore next*/exports.Scope = Scope;
exports.Scope = Scope;
var /*istanbul ignore next*/_babelTypes = require("babel-types");
var _babelTypes = require("babel-types");
/*istanbul ignore next*/
var t = _interopRequireWildcard(_babelTypes);
/*istanbul ignore next*/
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var ModuleDeclaration = /*istanbul ignore next*/exports.ModuleDeclaration = { /*istanbul ignore next*/
var ModuleDeclaration = exports.ModuleDeclaration = {
enter: function enter(path, file) {
/*istanbul ignore next*/var node = path.node;
var node = path.node;
if (node.source) {
node.source.value = file.resolveModuleSource(node.source.value);
@@ -30,9 +28,9 @@ var ModuleDeclaration = /*istanbul ignore next*/exports.ModuleDeclaration = { /*
}
};
var ImportDeclaration = /*istanbul ignore next*/exports.ImportDeclaration = { /*istanbul ignore next*/
var ImportDeclaration = exports.ImportDeclaration = {
exit: function exit(path, file) {
/*istanbul ignore next*/var node = path.node;
var node = path.node;
var specifiers = [];
@@ -43,8 +41,7 @@ var ImportDeclaration = /*istanbul ignore next*/exports.ImportDeclaration = { /*
specifiers: specifiers
});
for ( /*istanbul ignore next*/var _iterator = path.get("specifiers"), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
/*istanbul ignore next*/
for (var _iterator = path.get("specifiers"), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
@@ -91,14 +88,12 @@ var ImportDeclaration = /*istanbul ignore next*/exports.ImportDeclaration = { /*
};
function ExportDeclaration(path, file) {
/*istanbul ignore next*/var node = path.node;
var node = path.node;
var source = node.source ? node.source.value : null;
var exports = file.metadata.modules.exports;
// export function foo() {}
// export let foo = "bar";
var declar = path.get("declaration");
if (declar.isStatement()) {
var bindings = declar.getBindingIdentifiers();
@@ -114,8 +109,7 @@ function ExportDeclaration(path, file) {
}
if (path.isExportNamedDeclaration() && node.specifiers) {
for ( /*istanbul ignore next*/var _iterator2 = node.specifiers, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
/*istanbul ignore next*/
for (var _iterator2 = node.specifiers, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
var _ref2;
if (_isArray2) {
@@ -132,7 +126,6 @@ function ExportDeclaration(path, file) {
var exported = specifier.exported.name;
exports.exported.push(exported);
// export foo from "bar";
if (t.isExportDefaultSpecifier(specifier)) {
exports.specifiers.push({
kind: "external",
@@ -142,7 +135,6 @@ function ExportDeclaration(path, file) {
});
}
// export * as foo from "bar";
if (t.isExportNamespaceSpecifier(specifier)) {
exports.specifiers.push({
kind: "external-namespace",
@@ -154,8 +146,6 @@ function ExportDeclaration(path, file) {
var local = specifier.local;
if (!local) continue;
// export { foo } from "bar";
// export { foo as bar } from "bar";
if (source) {
exports.specifiers.push({
kind: "external",
@@ -165,8 +155,6 @@ function ExportDeclaration(path, file) {
});
}
// export { foo };
// export { foo as bar };
if (!source) {
exports.specifiers.push({
kind: "local",
@@ -177,7 +165,6 @@ function ExportDeclaration(path, file) {
}
}
// export * from "bar";
if (path.isExportAllDeclaration()) {
exports.specifiers.push({
kind: "external-all",
@@ -24,10 +24,6 @@ var _pathIsAbsolute = require("path-is-absolute");
var _pathIsAbsolute2 = _interopRequireDefault(_pathIsAbsolute);
var _pathExists = require("path-exists");
var _pathExists2 = _interopRequireDefault(_pathExists);
var _path = require("path");
var _path2 = _interopRequireDefault(_path);
@@ -48,20 +44,19 @@ var PACKAGE_FILENAME = "package.json";
function exists(filename) {
var cached = existsCache[filename];
if (cached == null) {
return existsCache[filename] = _pathExists2.default.sync(filename);
return existsCache[filename] = _fs2.default.existsSync(filename);
} else {
return cached;
}
}
function buildConfigChain() {
var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var log = arguments[1];
var filename = opts.filename;
var builder = new ConfigChainBuilder(log);
// resolve all .babelrc files
if (opts.babelrc !== false) {
builder.findConfigs(filename);
}
@@ -140,7 +135,7 @@ var ConfigChainBuilder = function () {
};
ConfigChainBuilder.prototype.addConfig = function addConfig(loc, key) {
var json = arguments.length <= 2 || arguments[2] === undefined ? _json2.default : arguments[2];
var json = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _json2.default;
if (this.resolvedConfigs.indexOf(loc) >= 0) {
return false;
@@ -183,7 +178,6 @@ var ConfigChainBuilder = function () {
dirname = dirname || process.cwd();
loc = loc || alias;
// add extends clause
if (options.extends) {
var extendsLoc = (0, _resolve2.default)(options.extends, dirname);
if (extendsLoc) {
@@ -201,7 +195,6 @@ var ConfigChainBuilder = function () {
dirname: dirname
});
// env
var envOpts = void 0;
var envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development";
if (options.env) {
+16 -3
View File
@@ -1,6 +1,4 @@
/*istanbul ignore next*/"use strict";
/* eslint max-len: 0 */
"use strict";
module.exports = {
filename: {
@@ -104,6 +102,11 @@ module.exports = {
description: "optional callback to control whether a comment should be inserted, when this is used the comments option is ignored"
},
wrapPluginVisitorMethod: {
hidden: true,
description: "optional callback to wrap all visitor methods"
},
compact: {
type: "booleanString",
default: "auto",
@@ -194,5 +197,15 @@ module.exports = {
type: "boolean",
default: false,
hidden: true
},
parserOpts: {
description: "Options to pass into the parser, or to change parsers (parserOpts.parser)",
default: false
},
generatorOpts: {
description: "Options to pass into the generator, or to change generators (generatorOpts.generator)",
default: false
}
};
+6 -8
View File
@@ -1,17 +1,15 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
exports.config = undefined;
exports.normaliseOptions = normaliseOptions;
var /*istanbul ignore next*/_parsers = require("./parsers");
var _parsers = require("./parsers");
/*istanbul ignore next*/
var parsers = _interopRequireWildcard(_parsers);
var /*istanbul ignore next*/_config = require("./config");
var _config = require("./config");
/*istanbul ignore next*/
var _config2 = _interopRequireDefault(_config);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -20,14 +18,14 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
exports.config = _config2.default;
function normaliseOptions() {
/*istanbul ignore next*/var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
for (var key in options) {
var val = options[key];
if (val == null) continue;
var opt = /*istanbul ignore next*/_config2.default[key];
if (opt && opt.alias) opt = /*istanbul ignore next*/_config2.default[opt.alias];
var opt = _config2.default[key];
if (opt && opt.alias) opt = _config2.default[opt.alias];
if (!opt) continue;
var parser = parsers[opt.type];
+144 -280
View File
@@ -1,7 +1,11 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
var _objectWithoutProperties2 = require("babel-runtime/helpers/objectWithoutProperties");
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _stringify = require("babel-runtime/core-js/json/stringify");
var _stringify2 = _interopRequireDefault(_stringify);
@@ -22,103 +26,59 @@ var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var /*istanbul ignore next*/_node = require("../../../api/node");
var _node = require("../../../api/node");
/*istanbul ignore next*/
var context = _interopRequireWildcard(_node);
var /*istanbul ignore next*/_plugin2 = require("../../plugin");
var _plugin2 = require("../../plugin");
/*istanbul ignore next*/
var _plugin3 = _interopRequireDefault(_plugin2);
var /*istanbul ignore next*/_babelMessages = require("babel-messages");
var _babelMessages = require("babel-messages");
/*istanbul ignore next*/
var messages = _interopRequireWildcard(_babelMessages);
var /*istanbul ignore next*/_index = require("./index");
var _index = require("./index");
var /*istanbul ignore next*/_resolve = require("../../../helpers/resolve");
var _resolve = require("../../../helpers/resolve");
/*istanbul ignore next*/
var _resolve2 = _interopRequireDefault(_resolve);
var /*istanbul ignore next*/_json = require("json5");
var _cloneDeepWith = require("lodash/cloneDeepWith");
/*istanbul ignore next*/
var _json2 = _interopRequireDefault(_json);
var _cloneDeepWith2 = _interopRequireDefault(_cloneDeepWith);
var /*istanbul ignore next*/_pathIsAbsolute = require("path-is-absolute");
var _clone = require("lodash/clone");
/*istanbul ignore next*/
var _pathIsAbsolute2 = _interopRequireDefault(_pathIsAbsolute);
var /*istanbul ignore next*/_pathExists = require("path-exists");
/*istanbul ignore next*/
var _pathExists2 = _interopRequireDefault(_pathExists);
var /*istanbul ignore next*/_cloneDeep = require("lodash/lang/cloneDeep");
/*istanbul ignore next*/
var _cloneDeep2 = _interopRequireDefault(_cloneDeep);
var /*istanbul ignore next*/_clone = require("lodash/lang/clone");
/*istanbul ignore next*/
var _clone2 = _interopRequireDefault(_clone);
var /*istanbul ignore next*/_merge = require("../../../helpers/merge");
var _merge = require("../../../helpers/merge");
/*istanbul ignore next*/
var _merge2 = _interopRequireDefault(_merge);
var /*istanbul ignore next*/_config = require("./config");
var _config2 = require("./config");
/*istanbul ignore next*/
var _config2 = _interopRequireDefault(_config);
var _config3 = _interopRequireDefault(_config2);
var /*istanbul ignore next*/_removed = require("./removed");
var _removed = require("./removed");
/*istanbul ignore next*/
var _removed2 = _interopRequireDefault(_removed);
var /*istanbul ignore next*/_path = require("path");
var _buildConfigChain = require("./build-config-chain");
var _buildConfigChain2 = _interopRequireDefault(_buildConfigChain);
var _path = require("path");
/*istanbul ignore next*/
var _path2 = _interopRequireDefault(_path);
var /*istanbul ignore next*/_fs = require("fs");
/*istanbul ignore next*/
var _fs2 = _interopRequireDefault(_fs);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var existsCache = {}; /* eslint max-len: 0 */
var jsonCache = {};
var BABELIGNORE_FILENAME = ".babelignore";
var BABELRC_FILENAME = ".babelrc";
var PACKAGE_FILENAME = "package.json";
function exists(filename) {
var cached = existsCache[filename];
if (cached == null) {
return existsCache[filename] = /*istanbul ignore next*/_pathExists2.default.sync(filename);
} else {
return cached;
}
}
/*istanbul ignore next*/
var OptionManager = function () {
function /*istanbul ignore next*/OptionManager(log) {
/*istanbul ignore next*/(0, _classCallCheck3.default)(this, OptionManager);
function OptionManager(log) {
(0, _classCallCheck3.default)(this, OptionManager);
this.resolvedConfigs = [];
this.options = OptionManager.createBareOptions();
@@ -126,8 +86,7 @@ var OptionManager = function () {
}
OptionManager.memoisePluginContainer = function memoisePluginContainer(fn, loc, i, alias) {
for ( /*istanbul ignore next*/var _iterator = OptionManager.memoisedPlugins, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
/*istanbul ignore next*/
for (var _iterator = OptionManager.memoisedPlugins, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
@@ -144,7 +103,7 @@ var OptionManager = function () {
if (cache.container === fn) return cache.plugin;
}
var obj = /*istanbul ignore next*/void 0;
var obj = void 0;
if (typeof fn === "function") {
obj = fn(context);
@@ -152,24 +111,24 @@ var OptionManager = function () {
obj = fn;
}
if ( /*istanbul ignore next*/(typeof obj === "undefined" ? "undefined" : (0, _typeof3.default)(obj)) === "object") {
var _plugin = new /*istanbul ignore next*/_plugin3.default(obj, alias);
if ((typeof obj === "undefined" ? "undefined" : (0, _typeof3.default)(obj)) === "object") {
var _plugin = new _plugin3.default(obj, alias);
OptionManager.memoisedPlugins.push({
container: fn,
plugin: _plugin
});
return _plugin;
} else {
throw new TypeError(messages.get("pluginNotObject", loc, i, /*istanbul ignore next*/typeof obj === "undefined" ? "undefined" : (0, _typeof3.default)(obj)) + loc + i);
throw new TypeError(messages.get("pluginNotObject", loc, i, typeof obj === "undefined" ? "undefined" : (0, _typeof3.default)(obj)) + loc + i);
}
};
OptionManager.createBareOptions = function createBareOptions() {
var opts = {};
for (var _key in /*istanbul ignore next*/_config2.default) {
var opt = /*istanbul ignore next*/_config2.default[_key];
opts[_key] = /*istanbul ignore next*/(0, _clone2.default)(opt.default);
for (var _key in _config3.default) {
var opt = _config3.default[_key];
opts[_key] = (0, _clone2.default)(opt.default);
}
return opts;
@@ -178,12 +137,11 @@ var OptionManager = function () {
OptionManager.normalisePlugin = function normalisePlugin(plugin, loc, i, alias) {
plugin = plugin.__esModule ? plugin.default : plugin;
if (!(plugin instanceof /*istanbul ignore next*/_plugin3.default)) {
// allow plugin containers to be specified so they don't have to manually require
if (typeof plugin === "function" || /*istanbul ignore next*/(typeof plugin === "undefined" ? "undefined" : (0, _typeof3.default)(plugin)) === "object") {
if (!(plugin instanceof _plugin3.default)) {
if (typeof plugin === "function" || (typeof plugin === "undefined" ? "undefined" : (0, _typeof3.default)(plugin)) === "object") {
plugin = OptionManager.memoisePluginContainer(plugin, loc, i, alias);
} else {
throw new TypeError(messages.get("pluginNotFunction", loc, i, /*istanbul ignore next*/typeof plugin === "undefined" ? "undefined" : (0, _typeof3.default)(plugin)));
throw new TypeError(messages.get("pluginNotFunction", loc, i, typeof plugin === "undefined" ? "undefined" : (0, _typeof3.default)(plugin)));
}
}
@@ -194,26 +152,24 @@ var OptionManager = function () {
OptionManager.normalisePlugins = function normalisePlugins(loc, dirname, plugins) {
return plugins.map(function (val, i) {
var plugin = /*istanbul ignore next*/void 0,
options = /*istanbul ignore next*/void 0;
var plugin = void 0,
options = void 0;
if (!val) {
throw new TypeError("Falsy value found in plugins");
}
// destructure plugins
if (Array.isArray(val)) {
/*istanbul ignore next*/plugin = val[0];
/*istanbul ignore next*/options = val[1];
plugin = val[0];
options = val[1];
} else {
plugin = val;
}
var alias = typeof plugin === "string" ? plugin : /*istanbul ignore next*/loc + "$" + i;
var alias = typeof plugin === "string" ? plugin : loc + "$" + i;
// allow plugins to be specified as strings
if (typeof plugin === "string") {
var pluginLoc = /*istanbul ignore next*/(0, _resolve2.default)( /*istanbul ignore next*/"babel-plugin-" + plugin, dirname) || /*istanbul ignore next*/(0, _resolve2.default)(plugin, dirname);
var pluginLoc = (0, _resolve2.default)("babel-plugin-" + plugin, dirname) || (0, _resolve2.default)(plugin, dirname);
if (pluginLoc) {
plugin = require(pluginLoc);
} else {
@@ -227,114 +183,56 @@ var OptionManager = function () {
});
};
OptionManager.prototype.addConfig = function addConfig(loc, key) {
/*istanbul ignore next*/var json = arguments.length <= 2 || arguments[2] === undefined ? _json2.default : arguments[2];
if (this.resolvedConfigs.indexOf(loc) >= 0) {
return false;
}
var content = /*istanbul ignore next*/_fs2.default.readFileSync(loc, "utf8");
var opts = /*istanbul ignore next*/void 0;
try {
opts = jsonCache[content] = jsonCache[content] || json.parse(content);
if (key) opts = opts[key];
} catch (err) {
err.message = /*istanbul ignore next*/loc + ": Error while parsing JSON - " + err.message;
throw err;
}
this.mergeOptions({
options: opts,
alias: loc,
dirname: /*istanbul ignore next*/_path2.default.dirname(loc)
});
this.resolvedConfigs.push(loc);
return !!opts;
};
/**
* This is called when we want to merge the input `opts` into the
* base options (passed as the `extendingOpts`: at top-level it's the
* main options, at presets level it's presets options).
*
* - `alias` is used to output pretty traces back to the original source.
* - `loc` is used to point to the original config.
* - `dirname` is used to resolve plugins relative to it.
*/
OptionManager.prototype.mergeOptions = function mergeOptions(_ref2) {
/*istanbul ignore next*/
var _this = this;
var rawOpts = _ref2.options;
/*istanbul ignore next*/var extendingOpts = _ref2.extending;
/*istanbul ignore next*/var alias = _ref2.alias;
/*istanbul ignore next*/var loc = _ref2.loc;
/*istanbul ignore next*/var dirname = _ref2.dirname;
var extendingOpts = _ref2.extending;
var alias = _ref2.alias;
var loc = _ref2.loc;
var dirname = _ref2.dirname;
alias = alias || "foreign";
if (!rawOpts) return;
//
if ( /*istanbul ignore next*/(typeof rawOpts === "undefined" ? "undefined" : (0, _typeof3.default)(rawOpts)) !== "object" || Array.isArray(rawOpts)) {
this.log.error( /*istanbul ignore next*/"Invalid options type for " + alias, TypeError);
if ((typeof rawOpts === "undefined" ? "undefined" : (0, _typeof3.default)(rawOpts)) !== "object" || Array.isArray(rawOpts)) {
this.log.error("Invalid options type for " + alias, TypeError);
}
//
var opts = /*istanbul ignore next*/(0, _cloneDeep2.default)(rawOpts, function (val) {
if (val instanceof /*istanbul ignore next*/_plugin3.default) {
var opts = (0, _cloneDeepWith2.default)(rawOpts, function (val) {
if (val instanceof _plugin3.default) {
return val;
}
});
//
dirname = dirname || process.cwd();
loc = loc || alias;
for (var _key2 in opts) {
var option = /*istanbul ignore next*/_config2.default[_key2];
var option = _config3.default[_key2];
// check for an unknown option
if (!option && this.log) {
var pluginOptsInfo = "Check out http://babeljs.io/docs/usage/options/ for more info";
if ( /*istanbul ignore next*/_removed2.default[_key2]) {
this.log.error( /*istanbul ignore next*/"Using removed Babel 5 option: " + alias + "." + _key2 + " - " + /*istanbul ignore next*/_removed2.default[_key2].message, ReferenceError);
if (_removed2.default[_key2]) {
this.log.error("Using removed Babel 5 option: " + alias + "." + _key2 + " - " + _removed2.default[_key2].message, ReferenceError);
} else {
this.log.error( /*istanbul ignore next*/"Unknown option: " + alias + "." + _key2 + ". " + pluginOptsInfo, ReferenceError);
var unknownOptErr = "Unknown option: " + alias + "." + _key2 + ". Check out http://babeljs.io/docs/usage/options/ for more information about options.";
var presetConfigErr = "A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:\n\nInvalid:\n `{ presets: [{option: value}] }`\nValid:\n `{ presets: ['pluginName', {option: value}] }`\n\nFor more detailed information on preset configuration, please see http://babeljs.io/docs/plugins/#pluginpresets-options.";
this.log.error(unknownOptErr + "\n\n" + presetConfigErr, ReferenceError);
}
}
}
// normalise options
/*istanbul ignore next*/(0, _index.normaliseOptions)(opts);
(0, _index.normaliseOptions)(opts);
// resolve plugins
if (opts.plugins) {
opts.plugins = OptionManager.normalisePlugins(loc, dirname, opts.plugins);
}
// add extends clause
if (opts.extends) {
var extendsLoc = /*istanbul ignore next*/(0, _resolve2.default)(opts.extends, dirname);
if (extendsLoc) {
this.addConfig(extendsLoc);
} else {
if (this.log) this.log.error( /*istanbul ignore next*/"Couldn't resolve extends clause of " + opts.extends + " in " + alias);
}
delete opts.extends;
}
// resolve presets
if (opts.presets) {
// If we're in the "pass per preset" mode, we resolve the presets
// and keep them for further execution to calculate the options.
if (opts.passPerPreset) {
opts.presets = this.resolvePresets(opts.presets, dirname, function (preset, presetLoc) {
/*istanbul ignore next*/_this.mergeOptions({
_this.mergeOptions({
options: preset,
extending: preset,
alias: presetLoc,
@@ -343,147 +241,111 @@ var OptionManager = function () {
});
});
} else {
// Otherwise, just merge presets options into the main options.
this.mergePresets(opts.presets, dirname);
delete opts.presets;
}
}
// env
var envOpts = /*istanbul ignore next*/void 0;
var envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development";
if (opts.env) {
envOpts = opts.env[envKey];
delete opts.env;
}
// Merge them into current extending options in case of top-level
// options. In case of presets, just re-assign options which are got
// normalized during the `mergeOptions`.
if (rawOpts === extendingOpts) {
/*istanbul ignore next*/(0, _assign2.default)(extendingOpts, opts);
(0, _assign2.default)(extendingOpts, opts);
} else {
/*istanbul ignore next*/(0, _merge2.default)(extendingOpts || this.options, opts);
(0, _merge2.default)(extendingOpts || this.options, opts);
}
// merge in env options
this.mergeOptions({
options: envOpts,
extending: extendingOpts,
alias: /*istanbul ignore next*/alias + ".env." + envKey,
dirname: dirname
});
};
/**
* Merges all presets into the main options in case we are not in the
* "pass per preset" mode. Otherwise, options are calculated per preset.
*/
OptionManager.prototype.mergePresets = function mergePresets(presets, dirname) {
/*istanbul ignore next*/
var _this2 = this;
this.resolvePresets(presets, dirname, function (presetOpts, presetLoc) {
/*istanbul ignore next*/_this2.mergeOptions({
_this2.mergeOptions({
options: presetOpts,
alias: presetLoc,
loc: presetLoc,
dirname: /*istanbul ignore next*/_path2.default.dirname(presetLoc || "")
dirname: _path2.default.dirname(presetLoc || "")
});
});
};
/**
* Resolves presets options which can be either direct object data,
* or a module name to require.
*/
OptionManager.prototype.resolvePresets = function resolvePresets(presets, dirname, onResolve) {
return presets.map(function (val) {
if (typeof val === "string") {
var presetLoc = /*istanbul ignore next*/(0, _resolve2.default)( /*istanbul ignore next*/"babel-preset-" + val, dirname) || /*istanbul ignore next*/(0, _resolve2.default)(val, dirname);
var options = void 0;
if (Array.isArray(val)) {
if (val.length > 2) {
throw new Error("Unexpected extra options " + (0, _stringify2.default)(val.slice(2)) + " passed to preset.");
}
var _val = val;
val = _val[0];
options = _val[1];
}
var presetLoc = void 0;
try {
if (typeof val === "string") {
presetLoc = (0, _resolve2.default)("babel-preset-" + val, dirname) || (0, _resolve2.default)(val, dirname);
if (!presetLoc) {
var matches = val.match(/^(@[^/]+)\/(.+)$/);
if (matches) {
var orgName = matches[1];
var presetPath = matches[2];
val = orgName + "/babel-preset-" + presetPath;
presetLoc = (0, _resolve2.default)(val, dirname);
}
}
if (!presetLoc) {
throw new Error("Couldn't find preset " + (0, _stringify2.default)(val) + " relative to directory " + (0, _stringify2.default)(dirname));
}
val = require(presetLoc);
}
if ((typeof val === "undefined" ? "undefined" : (0, _typeof3.default)(val)) === "object" && val.__esModule) {
if (val.default) {
val = val.default;
} else {
var _val2 = val;
var __esModule = _val2.__esModule;
var rest = (0, _objectWithoutProperties3.default)(_val2, ["__esModule"]);
val = rest;
}
}
if ((typeof val === "undefined" ? "undefined" : (0, _typeof3.default)(val)) === "object" && val.buildPreset) val = val.buildPreset;
if (typeof val !== "function" && options !== undefined) {
throw new Error("Options " + (0, _stringify2.default)(options) + " passed to " + (presetLoc || "a preset") + " which does not accept options.");
}
if (typeof val === "function") val = val(context, options);
if ((typeof val === "undefined" ? "undefined" : (0, _typeof3.default)(val)) !== "object") {
throw new Error("Unsupported preset format: " + val + ".");
}
onResolve && onResolve(val, presetLoc);
} catch (e) {
if (presetLoc) {
var _val = require(presetLoc);
onResolve && onResolve(_val, presetLoc);
return _val;
} else {
throw new Error( /*istanbul ignore next*/"Couldn't find preset " + /*istanbul ignore next*/(0, _stringify2.default)(val) + " relative to directory " + /*istanbul ignore next*/(0, _stringify2.default)(dirname));
e.message += " (While processing preset: " + (0, _stringify2.default)(presetLoc) + ")";
}
} else if ( /*istanbul ignore next*/(typeof val === "undefined" ? "undefined" : (0, _typeof3.default)(val)) === "object") {
onResolve && onResolve(val);
return val;
} else {
throw new Error( /*istanbul ignore next*/"Unsupported preset format: " + val + ".");
throw e;
}
return val;
});
};
OptionManager.prototype.addIgnoreConfig = function addIgnoreConfig(loc) {
var file = /*istanbul ignore next*/_fs2.default.readFileSync(loc, "utf8");
var lines = file.split("\n");
lines = lines.map(function (line) /*istanbul ignore next*/{
return line.replace(/#(.*?)$/, "").trim();
}).filter(function (line) /*istanbul ignore next*/{
return !!line;
});
this.mergeOptions({
options: { ignore: lines },
loc: loc
});
};
OptionManager.prototype.findConfigs = function findConfigs(loc) {
if (!loc) return;
if (! /*istanbul ignore next*/(0, _pathIsAbsolute2.default)(loc)) {
loc = /*istanbul ignore next*/_path2.default.join(process.cwd(), loc);
}
var foundConfig = false;
var foundIgnore = false;
while (loc !== (loc = /*istanbul ignore next*/_path2.default.dirname(loc))) {
if (!foundConfig) {
var configLoc = /*istanbul ignore next*/_path2.default.join(loc, BABELRC_FILENAME);
if (exists(configLoc)) {
this.addConfig(configLoc);
foundConfig = true;
}
var pkgLoc = /*istanbul ignore next*/_path2.default.join(loc, PACKAGE_FILENAME);
if (!foundConfig && exists(pkgLoc)) {
foundConfig = this.addConfig(pkgLoc, "babel", JSON);
}
}
if (!foundIgnore) {
var ignoreLoc = /*istanbul ignore next*/_path2.default.join(loc, BABELIGNORE_FILENAME);
if (exists(ignoreLoc)) {
this.addIgnoreConfig(ignoreLoc);
foundIgnore = true;
}
}
if (foundIgnore && foundConfig) return;
}
};
OptionManager.prototype.normaliseOptions = function normaliseOptions() {
var opts = this.options;
for (var _key3 in /*istanbul ignore next*/_config2.default) {
var option = /*istanbul ignore next*/_config2.default[_key3];
for (var _key3 in _config3.default) {
var option = _config3.default[_key3];
var val = opts[_key3];
// optional
if (!val && option.optional) continue;
// aliases
if (option.alias) {
opts[option.alias] = opts[option.alias] || val;
} else {
@@ -493,23 +355,25 @@ var OptionManager = function () {
};
OptionManager.prototype.init = function init() {
/*istanbul ignore next*/var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var filename = opts.filename;
for (var _iterator2 = (0, _buildConfigChain2.default)(opts, this.log), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
var _ref3;
// resolve all .babelrc files
if (opts.babelrc !== false) {
this.findConfigs(filename);
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref3 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref3 = _i2.value;
}
var _config = _ref3;
this.mergeOptions(_config);
}
// merge in base options
this.mergeOptions({
options: opts,
alias: "base",
dirname: filename && /*istanbul ignore next*/_path2.default.dirname(filename)
});
// normalise
this.normaliseOptions(opts);
return this.options;
@@ -518,8 +382,8 @@ var OptionManager = function () {
return OptionManager;
}();
/*istanbul ignore next*/exports.default = OptionManager;
exports.default = OptionManager;
OptionManager.memoisedPlugins = [];
/*istanbul ignore next*/module.exports = exports["default"];
module.exports = exports["default"];
+6 -9
View File
@@ -1,27 +1,24 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
exports.filename = undefined;
exports.boolean = boolean;
/*istanbul ignore next*/exports.booleanString = booleanString;
/*istanbul ignore next*/exports.list = list;
exports.booleanString = booleanString;
exports.list = list;
var /*istanbul ignore next*/_slash = require("slash");
var _slash = require("slash");
/*istanbul ignore next*/
var _slash2 = _interopRequireDefault(_slash);
var /*istanbul ignore next*/_util = require("../../../util");
var _util = require("../../../util");
/*istanbul ignore next*/
var util = _interopRequireWildcard(_util);
/*istanbul ignore next*/
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var filename = /*istanbul ignore next*/exports.filename = _slash2.default;
var filename = exports.filename = _slash2.default;
function boolean(val) {
return !!val;
+2 -6
View File
@@ -1,6 +1,4 @@
/*istanbul ignore next*/"use strict";
/* eslint max-len: 0 */
"use strict";
module.exports = {
"auxiliaryComment": {
@@ -24,9 +22,7 @@ module.exports = {
"jsxPragma": {
"message": "use the `pragma` option in the `react-jsx` plugin . Check out http://babeljs.io/docs/plugins/transform-react-jsx/"
},
// "keepModuleIdExtensions": {
// "message": ""
// },
"loose": {
"message": "Specify the `loose` option for the relevant plugin you are using or use a preset that sets the option."
},
+10 -21
View File
@@ -1,35 +1,25 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
var /*istanbul ignore next*/_plugin = require("../plugin");
var _plugin = require("../plugin");
/*istanbul ignore next*/
var _plugin2 = _interopRequireDefault(_plugin);
var /*istanbul ignore next*/_sortBy = require("lodash/collection/sortBy");
var _sortBy = require("lodash/sortBy");
/*istanbul ignore next*/
var _sortBy2 = _interopRequireDefault(_sortBy);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = new /*istanbul ignore next*/_plugin2.default({
/**
* [Please add a description.]
*
* Priority:
*
* - 0 We want this to be at the **very** bottom
* - 1 Default node position
* - 2 Priority over normal nodes
* - 3 We want this to be at the **very** top
*/
exports.default = new _plugin2.default({
name: "internal.blockHoist",
visitor: {
Block: { /*istanbul ignore next*/
Block: {
exit: function exit(_ref) {
/*istanbul ignore next*/var node = _ref.node;
var node = _ref.node;
var hasChange = false;
for (var i = 0; i < node.body.length; i++) {
@@ -41,16 +31,15 @@ exports.default = new /*istanbul ignore next*/_plugin2.default({
}
if (!hasChange) return;
node.body = /*istanbul ignore next*/(0, _sortBy2.default)(node.body, function (bodyNode) {
node.body = (0, _sortBy2.default)(node.body, function (bodyNode) {
var priority = bodyNode && bodyNode._blockHoist;
if (priority == null) priority = 1;
if (priority === true) priority = 2;
// Higher priorities should move toward the top.
return -1 * priority;
});
}
}
}
});
/*istanbul ignore next*/module.exports = exports["default"];
module.exports = exports["default"];
@@ -1,4 +1,4 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
@@ -6,28 +6,25 @@ var _symbol = require("babel-runtime/core-js/symbol");
var _symbol2 = _interopRequireDefault(_symbol);
var /*istanbul ignore next*/_plugin = require("../plugin");
var _plugin = require("../plugin");
/*istanbul ignore next*/
var _plugin2 = _interopRequireDefault(_plugin);
var /*istanbul ignore next*/_babelTypes = require("babel-types");
var _babelTypes = require("babel-types");
/*istanbul ignore next*/
var t = _interopRequireWildcard(_babelTypes);
/*istanbul ignore next*/
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var SUPER_THIS_BOUND = /*istanbul ignore next*/(0, _symbol2.default)("super this bound");
var SUPER_THIS_BOUND = (0, _symbol2.default)("super this bound");
var superVisitor = { /*istanbul ignore next*/
var superVisitor = {
CallExpression: function CallExpression(path) {
if (!path.get("callee").isSuper()) return;
/*istanbul ignore next*/var node = path.node;
var node = path.node;
if (node[SUPER_THIS_BOUND]) return;
node[SUPER_THIS_BOUND] = true;
@@ -36,12 +33,14 @@ var superVisitor = { /*istanbul ignore next*/
}
};
/*istanbul ignore next*/exports.default = new /*istanbul ignore next*/_plugin2.default({
visitor: { /*istanbul ignore next*/
exports.default = new _plugin2.default({
name: "internal.shadowFunctions",
visitor: {
ThisExpression: function ThisExpression(path) {
remap(path, "this");
},
/*istanbul ignore next*/ReferencedIdentifier: function ReferencedIdentifier(path) {
ReferencedIdentifier: function ReferencedIdentifier(path) {
if (path.node.name === "arguments") {
remap(path, "arguments");
}
@@ -59,30 +58,32 @@ function shouldShadow(path, shadowPath) {
}
function remap(path, key) {
// ensure that we're shadowed
var shadowPath = path.inShadow(key);
if (!shouldShadow(path, shadowPath)) return;
var shadowFunction = path.node._shadowedFunctionLiteral;
var currentFunction = /*istanbul ignore next*/void 0;
var currentFunction = void 0;
var passedShadowFunction = false;
var fnPath = path.findParent(function (path) {
if (path.isProgram() || path.isFunction()) {
// catch current function in case this is the shadowed one and we can ignore it
currentFunction = currentFunction || path;
var fnPath = path.find(function (innerPath) {
if (innerPath.parentPath && innerPath.parentPath.isClassProperty() && innerPath.key === "value") {
return true;
}
if (path === innerPath) return false;
if (innerPath.isProgram() || innerPath.isFunction()) {
currentFunction = currentFunction || innerPath;
}
if (path.isProgram()) {
if (innerPath.isProgram()) {
passedShadowFunction = true;
return true;
} else if (path.isFunction() && !path.isArrowFunctionExpression()) {
} else if (innerPath.isFunction() && !innerPath.isArrowFunctionExpression()) {
if (shadowFunction) {
if (path === shadowFunction || path.node === shadowFunction.node) return true;
if (innerPath === shadowFunction || innerPath.node === shadowFunction.node) return true;
} else {
if (!path.is("shadow")) return true;
if (!innerPath.is("shadow")) return true;
}
passedShadowFunction = true;
@@ -93,19 +94,13 @@ function remap(path, key) {
});
if (shadowFunction && fnPath.isProgram() && !shadowFunction.isProgram()) {
// If the shadow wasn't found, take the closest function as a backup.
// This is a bit of a hack, but it will allow the parameter transforms to work properly
// without introducing yet another shadow-controlling flag.
fnPath = path.findParent(function (p) /*istanbul ignore next*/{
fnPath = path.findParent(function (p) {
return p.isProgram() || p.isFunction();
});
}
// no point in realiasing if we're in this function
if (fnPath === currentFunction) return;
// If the only functions that were encountered are arrow functions, skip remapping the
// binding since arrow function syntax already does that.
if (!passedShadowFunction) return;
var cached = fnPath.getData(key);
@@ -115,16 +110,23 @@ function remap(path, key) {
fnPath.setData(key, id);
if (key === "this" && fnPath.isMethod({ kind: "constructor" })) {
var classPath = fnPath.findParent(function (p) {
return p.isClass();
});
var hasSuperClass = !!(classPath && classPath.node && classPath.node.superClass);
if (key === "this" && fnPath.isMethod({ kind: "constructor" }) && hasSuperClass) {
fnPath.scope.push({ id: id });
fnPath.traverse(superVisitor, { id: id });
} else {
var init = key === "this" ? t.thisExpression() : t.identifier(key);
if (shadowFunction) init._shadowedFunctionLiteral = shadowFunction;
fnPath.scope.push({ id: id, init: init });
}
return path.replaceWith(id);
}
/*istanbul ignore next*/module.exports = exports["default"];
module.exports = exports["default"];
+15 -19
View File
@@ -1,4 +1,4 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
@@ -6,19 +6,16 @@ var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var /*istanbul ignore next*/_normalizeAst = require("../helpers/normalize-ast");
var _normalizeAst = require("../helpers/normalize-ast");
/*istanbul ignore next*/
var _normalizeAst2 = _interopRequireDefault(_normalizeAst);
var /*istanbul ignore next*/_plugin = require("./plugin");
var _plugin = require("./plugin");
/*istanbul ignore next*/
var _plugin2 = _interopRequireDefault(_plugin);
var /*istanbul ignore next*/_file = require("./file");
var _file = require("./file");
/*istanbul ignore next*/
var _file2 = _interopRequireDefault(_file);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -29,7 +26,7 @@ var Pipeline = function () {
}
Pipeline.prototype.lint = function lint(code) {
/*istanbul ignore next*/var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
opts.code = false;
opts.mode = "lint";
@@ -37,7 +34,7 @@ var Pipeline = function () {
};
Pipeline.prototype.pretransform = function pretransform(code, opts) {
var file = new /*istanbul ignore next*/_file2.default(opts, this);
var file = new _file2.default(opts, this);
return file.wrap(code, function () {
file.addCode(code);
file.parseCode(code);
@@ -46,7 +43,7 @@ var Pipeline = function () {
};
Pipeline.prototype.transform = function transform(code, opts) {
var file = new /*istanbul ignore next*/_file2.default(opts, this);
var file = new _file2.default(opts, this);
return file.wrap(code, function () {
file.addCode(code);
file.parseCode(code);
@@ -55,21 +52,21 @@ var Pipeline = function () {
};
Pipeline.prototype.analyse = function analyse(code) {
/*istanbul ignore next*/var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
/*istanbul ignore next*/var visitor = arguments[2];
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var visitor = arguments[2];
opts.code = false;
if (visitor) {
opts.plugins = opts.plugins || [];
opts.plugins.push(new /*istanbul ignore next*/_plugin2.default({ visitor: visitor }));
opts.plugins.push(new _plugin2.default({ visitor: visitor }));
}
return this.transform(code, opts).metadata;
};
Pipeline.prototype.transformFromAst = function transformFromAst(ast, code, opts) {
ast = /*istanbul ignore next*/(0, _normalizeAst2.default)(ast);
ast = (0, _normalizeAst2.default)(ast);
var file = new /*istanbul ignore next*/_file2.default(opts, this);
var file = new _file2.default(opts, this);
return file.wrap(code, function () {
file.addCode(code);
file.addAst(ast);
@@ -78,8 +75,7 @@ var Pipeline = function () {
};
return Pipeline;
}(); /* global BabelFileResult, BabelFileMetadata */
}();
/*istanbul ignore next*/exports.default = Pipeline;
/*istanbul ignore next*/module.exports = exports["default"];
exports.default = Pipeline;
module.exports = exports["default"];
+18 -39
View File
@@ -1,4 +1,4 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
@@ -14,19 +14,12 @@ var _inherits2 = require("babel-runtime/helpers/inherits");
var _inherits3 = _interopRequireDefault(_inherits2);
var /*istanbul ignore next*/_store = require("../store");
var _store = require("../store");
/*istanbul ignore next*/
var _store2 = _interopRequireDefault(_store);
var /*istanbul ignore next*/_babelTraverse = require("babel-traverse");
var _file5 = require("./file");
/*istanbul ignore next*/
var _babelTraverse2 = _interopRequireDefault(_babelTraverse);
var /*istanbul ignore next*/_file5 = require("./file");
/*istanbul ignore next*/
var _file6 = _interopRequireDefault(_file5);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -34,59 +27,45 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
var PluginPass = function (_Store) {
(0, _inherits3.default)(PluginPass, _Store);
function /*istanbul ignore next*/PluginPass(file, plugin) {
/*istanbul ignore next*/var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
/*istanbul ignore next*/(0, _classCallCheck3.default)(this, PluginPass);
function PluginPass(file, plugin) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
(0, _classCallCheck3.default)(this, PluginPass);
var _this = (0, _possibleConstructorReturn3.default)(this, /*istanbul ignore next*/_Store.call( /*istanbul ignore next*/this));
var _this = (0, _possibleConstructorReturn3.default)(this, _Store.call(this));
/*istanbul ignore next*/_this.plugin = plugin;
/*istanbul ignore next*/_this.file = file;
/*istanbul ignore next*/_this.opts = options;
/*istanbul ignore next*/return _this;
_this.plugin = plugin;
_this.key = plugin.key;
_this.file = file;
_this.opts = options;
return _this;
}
PluginPass.prototype.transform = function transform() {
var file = this.file;
file.log.debug( /*istanbul ignore next*/"Start transformer " + this.key);
/*istanbul ignore next*/(0, _babelTraverse2.default)(file.ast, this.plugin.visitor, file.scope, file);
file.log.debug( /*istanbul ignore next*/"Finish transformer " + this.key);
};
PluginPass.prototype.addHelper = function addHelper() {
/*istanbul ignore next*/
var _file;
return (/*istanbul ignore next*/(_file = this.file).addHelper. /*istanbul ignore next*/apply( /*istanbul ignore next*/_file, /*istanbul ignore next*/arguments)
);
return (_file = this.file).addHelper.apply(_file, arguments);
};
PluginPass.prototype.addImport = function addImport() {
/*istanbul ignore next*/
var _file2;
return (/*istanbul ignore next*/(_file2 = this.file).addImport. /*istanbul ignore next*/apply( /*istanbul ignore next*/_file2, /*istanbul ignore next*/arguments)
);
return (_file2 = this.file).addImport.apply(_file2, arguments);
};
PluginPass.prototype.getModuleName = function getModuleName() {
/*istanbul ignore next*/
var _file3;
return (/*istanbul ignore next*/(_file3 = this.file).getModuleName. /*istanbul ignore next*/apply( /*istanbul ignore next*/_file3, /*istanbul ignore next*/arguments)
);
return (_file3 = this.file).getModuleName.apply(_file3, arguments);
};
PluginPass.prototype.buildCodeFrameError = function buildCodeFrameError() {
/*istanbul ignore next*/
var _file4;
return (/*istanbul ignore next*/(_file4 = this.file).buildCodeFrameError. /*istanbul ignore next*/apply( /*istanbul ignore next*/_file4, /*istanbul ignore next*/arguments)
);
return (_file4 = this.file).buildCodeFrameError.apply(_file4, arguments);
};
return PluginPass;
}(_store2.default);
/*istanbul ignore next*/exports.default = PluginPass;
/*istanbul ignore next*/module.exports = exports["default"];
exports.default = PluginPass;
module.exports = exports["default"];
+27 -43
View File
@@ -1,4 +1,4 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
@@ -18,62 +18,53 @@ var _inherits2 = require("babel-runtime/helpers/inherits");
var _inherits3 = _interopRequireDefault(_inherits2);
var /*istanbul ignore next*/_optionManager = require("./file/options/option-manager");
var _optionManager = require("./file/options/option-manager");
/*istanbul ignore next*/
var _optionManager2 = _interopRequireDefault(_optionManager);
var /*istanbul ignore next*/_babelMessages = require("babel-messages");
var _babelMessages = require("babel-messages");
/*istanbul ignore next*/
var messages = _interopRequireWildcard(_babelMessages);
var /*istanbul ignore next*/_store = require("../store");
var _store = require("../store");
/*istanbul ignore next*/
var _store2 = _interopRequireDefault(_store);
var /*istanbul ignore next*/_babelTraverse = require("babel-traverse");
var _babelTraverse = require("babel-traverse");
/*istanbul ignore next*/
var _babelTraverse2 = _interopRequireDefault(_babelTraverse);
var /*istanbul ignore next*/_assign = require("lodash/object/assign");
var _assign = require("lodash/assign");
/*istanbul ignore next*/
var _assign2 = _interopRequireDefault(_assign);
var /*istanbul ignore next*/_clone = require("lodash/lang/clone");
var _clone = require("lodash/clone");
/*istanbul ignore next*/
var _clone2 = _interopRequireDefault(_clone);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint max-len: 0 */
var GLOBAL_VISITOR_PROPS = ["enter", "exit"];
/*istanbul ignore next*/
var Plugin = function (_Store) {
(0, _inherits3.default)(Plugin, _Store);
function /*istanbul ignore next*/Plugin(plugin, key) {
/*istanbul ignore next*/(0, _classCallCheck3.default)(this, Plugin);
function Plugin(plugin, key) {
(0, _classCallCheck3.default)(this, Plugin);
var _this = (0, _possibleConstructorReturn3.default)(this, /*istanbul ignore next*/_Store.call( /*istanbul ignore next*/this));
var _this = (0, _possibleConstructorReturn3.default)(this, _Store.call(this));
/*istanbul ignore next*/_this.initialized = false;
/*istanbul ignore next*/_this.raw = /*istanbul ignore next*/(0, _assign2.default)({}, plugin);
/*istanbul ignore next*/_this.key = key;
_this.initialized = false;
_this.raw = (0, _assign2.default)({}, plugin);
_this.key = _this.take("name") || key;
/*istanbul ignore next*/_this.manipulateOptions = /*istanbul ignore next*/_this.take("manipulateOptions");
/*istanbul ignore next*/_this.post = /*istanbul ignore next*/_this.take("post");
/*istanbul ignore next*/_this.pre = /*istanbul ignore next*/_this.take("pre");
/*istanbul ignore next*/_this.visitor = /*istanbul ignore next*/_this.normaliseVisitor( /*istanbul ignore next*/(0, _clone2.default)( /*istanbul ignore next*/_this.take("visitor")) || {});
/*istanbul ignore next*/return _this;
_this.manipulateOptions = _this.take("manipulateOptions");
_this.post = _this.take("post");
_this.pre = _this.take("pre");
_this.visitor = _this.normaliseVisitor((0, _clone2.default)(_this.take("visitor")) || {});
return _this;
}
Plugin.prototype.take = function take(key) {
@@ -89,14 +80,13 @@ var Plugin = function (_Store) {
var fns = [target[key], this[key]];
return function () {
var val = /*istanbul ignore next*/void 0;
/*istanbul ignore next*/
var val = void 0;
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
for ( /*istanbul ignore next*/var _iterator = fns, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
/*istanbul ignore next*/
for (var _iterator = fns, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
@@ -123,19 +113,14 @@ var Plugin = function (_Store) {
var inherits = this.take("inherits");
if (!inherits) return;
inherits = /*istanbul ignore next*/_optionManager2.default.normalisePlugin(inherits, loc, "inherits");
inherits = _optionManager2.default.normalisePlugin(inherits, loc, "inherits");
this.manipulateOptions = this.chain(inherits, "manipulateOptions");
this.post = this.chain(inherits, "post");
this.pre = this.chain(inherits, "pre");
this.visitor = /*istanbul ignore next*/_babelTraverse2.default.visitors.merge([inherits.visitor, this.visitor]);
this.visitor = _babelTraverse2.default.visitors.merge([inherits.visitor, this.visitor]);
};
/**
* We lazy initialise parts of a plugin that rely on contextual information such as
* position on disk and how it was specified.
*/
Plugin.prototype.init = function init(loc, i) {
if (this.initialized) return;
this.initialized = true;
@@ -148,8 +133,7 @@ var Plugin = function (_Store) {
};
Plugin.prototype.normaliseVisitor = function normaliseVisitor(visitor) {
for ( /*istanbul ignore next*/var _iterator2 = GLOBAL_VISITOR_PROPS, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
/*istanbul ignore next*/
for (var _iterator2 = GLOBAL_VISITOR_PROPS, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
var _ref2;
if (_isArray2) {
@@ -168,12 +152,12 @@ var Plugin = function (_Store) {
}
}
/*istanbul ignore next*/_babelTraverse2.default.explode(visitor);
_babelTraverse2.default.explode(visitor);
return visitor;
};
return Plugin;
}(_store2.default);
/*istanbul ignore next*/exports.default = Plugin;
/*istanbul ignore next*/module.exports = exports["default"];
exports.default = Plugin;
module.exports = exports["default"];
+33 -80
View File
@@ -1,4 +1,4 @@
/*istanbul ignore next*/"use strict";
"use strict";
exports.__esModule = true;
exports.inspect = exports.inherits = undefined;
@@ -15,87 +15,65 @@ Object.defineProperty(exports, "inherits", {
return _util.inherits;
}
});
/*istanbul ignore next*/Object.defineProperty(exports, "inspect", {
Object.defineProperty(exports, "inspect", {
enumerable: true,
get: function get() {
return _util.inspect;
}
});
/*istanbul ignore next*/exports.canCompile = canCompile;
/*istanbul ignore next*/exports.list = list;
/*istanbul ignore next*/exports.regexify = regexify;
/*istanbul ignore next*/exports.arrayify = arrayify;
/*istanbul ignore next*/exports.booleanify = booleanify;
/*istanbul ignore next*/exports.shouldIgnore = shouldIgnore;
exports.canCompile = canCompile;
exports.list = list;
exports.regexify = regexify;
exports.arrayify = arrayify;
exports.booleanify = booleanify;
exports.shouldIgnore = shouldIgnore;
var /*istanbul ignore next*/_escapeRegExp = require("lodash/string/escapeRegExp");
var _escapeRegExp = require("lodash/escapeRegExp");
/*istanbul ignore next*/
var _escapeRegExp2 = _interopRequireDefault(_escapeRegExp);
var /*istanbul ignore next*/_startsWith = require("lodash/string/startsWith");
var _startsWith = require("lodash/startsWith");
/*istanbul ignore next*/
var _startsWith2 = _interopRequireDefault(_startsWith);
var /*istanbul ignore next*/_isBoolean = require("lodash/lang/isBoolean");
var _isBoolean = require("lodash/isBoolean");
/*istanbul ignore next*/
var _isBoolean2 = _interopRequireDefault(_isBoolean);
var /*istanbul ignore next*/_minimatch = require("minimatch");
var _minimatch = require("minimatch");
/*istanbul ignore next*/
var _minimatch2 = _interopRequireDefault(_minimatch);
var /*istanbul ignore next*/_contains = require("lodash/collection/contains");
var _includes = require("lodash/includes");
/*istanbul ignore next*/
var _contains2 = _interopRequireDefault(_contains);
var _includes2 = _interopRequireDefault(_includes);
var /*istanbul ignore next*/_isString = require("lodash/lang/isString");
var _isString = require("lodash/isString");
/*istanbul ignore next*/
var _isString2 = _interopRequireDefault(_isString);
var /*istanbul ignore next*/_isRegExp = require("lodash/lang/isRegExp");
var _isRegExp = require("lodash/isRegExp");
/*istanbul ignore next*/
var _isRegExp2 = _interopRequireDefault(_isRegExp);
var /*istanbul ignore next*/_path = require("path");
var _path = require("path");
/*istanbul ignore next*/
var _path2 = _interopRequireDefault(_path);
var /*istanbul ignore next*/_slash = require("slash");
var _slash = require("slash");
/*istanbul ignore next*/
var _slash2 = _interopRequireDefault(_slash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Test if a filename ends with a compilable extension.
*/
function canCompile(filename, altExts) {
var exts = altExts || canCompile.EXTENSIONS;
var ext = /*istanbul ignore next*/_path2.default.extname(filename);
return (/*istanbul ignore next*/(0, _contains2.default)(exts, ext)
);
var ext = _path2.default.extname(filename);
return (0, _includes2.default)(exts, ext);
}
/**
* Default set of compilable extensions.
*/
canCompile.EXTENSIONS = [".js", ".jsx", ".es6", ".es"];
/**
* Create an array from any value, splitting strings by ",".
*/
function list(val) {
if (!val) {
return [];
@@ -108,46 +86,36 @@ function list(val) {
}
}
/**
* Create a RegExp from a string, array, or regexp.
*/
function regexify(val) {
if (!val) {
return new RegExp(/.^/);
}
if (Array.isArray(val)) {
val = new RegExp(val.map( /*istanbul ignore next*/_escapeRegExp2.default).join("|"), "i");
val = new RegExp(val.map(_escapeRegExp2.default).join("|"), "i");
}
if (typeof val === "string") {
// normalise path separators
val = /*istanbul ignore next*/(0, _slash2.default)(val);
val = (0, _slash2.default)(val);
// remove starting wildcards or relative separator if present
if ( /*istanbul ignore next*/(0, _startsWith2.default)(val, "./") || /*istanbul ignore next*/(0, _startsWith2.default)(val, "*/")) val = val.slice(2);
if ( /*istanbul ignore next*/(0, _startsWith2.default)(val, "**/")) val = val.slice(3);
if ((0, _startsWith2.default)(val, "./") || (0, _startsWith2.default)(val, "*/")) val = val.slice(2);
if ((0, _startsWith2.default)(val, "**/")) val = val.slice(3);
var regex = /*istanbul ignore next*/_minimatch2.default.makeRe(val, { nocase: true });
var regex = _minimatch2.default.makeRe(val, { nocase: true });
return new RegExp(regex.source.slice(1, -1), "i");
}
if ( /*istanbul ignore next*/(0, _isRegExp2.default)(val)) {
if ((0, _isRegExp2.default)(val)) {
return val;
}
throw new TypeError("illegal type for regexify");
}
/**
* Create an array from a boolean, string, or array, mapped by and optional function.
*/
function arrayify(val, mapFn) {
if (!val) return [];
if ( /*istanbul ignore next*/(0, _isBoolean2.default)(val)) return arrayify([val], mapFn);
if ( /*istanbul ignore next*/(0, _isString2.default)(val)) return arrayify(list(val), mapFn);
if ((0, _isBoolean2.default)(val)) return arrayify([val], mapFn);
if ((0, _isString2.default)(val)) return arrayify(list(val), mapFn);
if (Array.isArray(val)) {
if (mapFn) val = val.map(mapFn);
@@ -157,10 +125,6 @@ function arrayify(val, mapFn) {
return [val];
}
/**
* Makes boolean-like strings into booleans.
*/
function booleanify(val) {
if (val === "true" || val == 1) {
return true;
@@ -173,19 +137,14 @@ function booleanify(val) {
return val;
}
/**
* Tests if a filename should be ignored based on "ignore" and "only" options.
*/
function shouldIgnore(filename) {
/*istanbul ignore next*/var ignore = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
/*istanbul ignore next*/var only = arguments[2];
var ignore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var only = arguments[2];
filename = /*istanbul ignore next*/(0, _slash2.default)(filename);
filename = filename.replace(/\\/g, "/");
if (only) {
for ( /*istanbul ignore next*/var _iterator = only, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
/*istanbul ignore next*/
for (var _iterator = only, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
@@ -203,8 +162,7 @@ function shouldIgnore(filename) {
}
return true;
} else if (ignore.length) {
for ( /*istanbul ignore next*/var _iterator2 = ignore, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
/*istanbul ignore next*/
for (var _iterator2 = ignore, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
var _ref2;
if (_isArray2) {
@@ -225,11 +183,6 @@ function shouldIgnore(filename) {
return false;
}
/**
* Returns result of calling function with filename if pattern is a function.
* Otherwise returns result of matching pattern Regex with filename.
*/
function _shouldIgnore(pattern, filename) {
if (typeof pattern === "function") {
return pattern(filename);
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../babylon/bin/babylon.js" "$@"
ret=$?
else
node "$basedir/../babylon/bin/babylon.js" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\babylon\bin\babylon.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\babylon\bin\babylon.js" %*
)
+42
View File
@@ -0,0 +1,42 @@
# babel-code-frame
> Generate errors that contain a code frame that point to source locations.
## Install
```sh
$ npm install babel-code-frame
```
## Usage
```js
import codeFrame from 'babel-code-frame';
const rawLines = `class Foo {
constructor()
}`;
const lineNumber = 2;
const colNumber = 16;
const result = codeFrame(rawLines, lineNumber, colNumber, { /* options */ });
console.log(result);
```
```sh
1 | class Foo {
> 2 | constructor()
| ^
3 | }
```
If the column number is not known, you may pass `null` instead.
## Options
name | type | default | description
-----------------------|----------|-----------------|------------------------------------------------------
highlightCode | boolean | `false` | Syntax highlight the code as JavaScript for terminals
linesAbove | number | 2 | The number of lines to show above the error
linesBelow | number | 3 | The number of lines to show below the error
+135
View File
@@ -0,0 +1,135 @@
"use strict";
exports.__esModule = true;
exports.default = function (rawLines, lineNumber, colNumber) {
var opts = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
colNumber = Math.max(colNumber, 0);
var highlighted = opts.highlightCode && _chalk2.default.supportsColor;
var maybeHighlight = function maybeHighlight(chalkFn, string) {
return highlighted ? chalkFn(string) : string;
};
if (highlighted) rawLines = highlight(rawLines);
var linesAbove = opts.linesAbove || 2;
var linesBelow = opts.linesBelow || 3;
var lines = rawLines.split(NEWLINE);
var start = Math.max(lineNumber - (linesAbove + 1), 0);
var end = Math.min(lines.length, lineNumber + linesBelow);
if (!lineNumber && !colNumber) {
start = 0;
end = lines.length;
}
var numberMaxWidth = String(end).length;
var frame = lines.slice(start, end).map(function (line, index) {
var number = start + 1 + index;
var paddedNumber = (" " + number).slice(-numberMaxWidth);
var gutter = " " + paddedNumber + " | ";
if (number === lineNumber) {
var markerLine = "";
if (colNumber) {
var markerSpacing = line.slice(0, colNumber - 1).replace(/[^\t]/g, " ");
markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^")].join("");
}
return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join("");
} else {
return " " + maybeHighlight(defs.gutter, gutter) + line;
}
}).join("\n");
if (highlighted) {
return _chalk2.default.reset(frame);
} else {
return frame;
}
};
var _jsTokens = require("js-tokens");
var _jsTokens2 = _interopRequireDefault(_jsTokens);
var _esutils = require("esutils");
var _esutils2 = _interopRequireDefault(_esutils);
var _chalk = require("chalk");
var _chalk2 = _interopRequireDefault(_chalk);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var defs = {
keyword: _chalk2.default.cyan,
capitalized: _chalk2.default.yellow,
jsx_tag: _chalk2.default.yellow,
punctuator: _chalk2.default.yellow,
number: _chalk2.default.magenta,
string: _chalk2.default.green,
regex: _chalk2.default.magenta,
comment: _chalk2.default.grey,
invalid: _chalk2.default.white.bgRed.bold,
gutter: _chalk2.default.grey,
marker: _chalk2.default.red.bold
};
var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
var JSX_TAG = /^[a-z][\w-]*$/i;
var BRACKET = /^[()\[\]{}]$/;
function getTokenType(match) {
var _match$slice = match.slice(-2);
var offset = _match$slice[0];
var text = _match$slice[1];
var token = _jsTokens2.default.matchToToken(match);
if (token.type === "name") {
if (_esutils2.default.keyword.isReservedWordES6(token.value)) {
return "keyword";
}
if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
return "jsx_tag";
}
if (token.value[0] !== token.value[0].toLowerCase()) {
return "capitalized";
}
}
if (token.type === "punctuator" && BRACKET.test(token.value)) {
return "bracket";
}
return token.type;
}
function highlight(text) {
return text.replace(_jsTokens2.default, function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var type = getTokenType(args);
var colorize = defs[type];
if (colorize) {
return args[0].split(NEWLINE).map(function (str) {
return colorize(str);
}).join("\n");
} else {
return args[0];
}
});
}
module.exports = exports["default"];
+103
View File
@@ -0,0 +1,103 @@
{
"_args": [
[
{
"raw": "babel-code-frame@^6.16.0",
"scope": null,
"escapedName": "babel-code-frame",
"name": "babel-code-frame",
"rawSpec": "^6.16.0",
"spec": ">=6.16.0 <7.0.0",
"type": "range"
},
"C:\\Users\\Lukas Obermann\\Projekte\\Cha5App\\code\\git\\node_modules\\babel-core"
]
],
"_from": "babel-code-frame@>=6.16.0 <7.0.0",
"_id": "babel-code-frame@6.16.0",
"_inCache": true,
"_location": "/babel-core/babel-code-frame",
"_nodeVersion": "5.11.1",
"_npmOperationalInternal": {
"host": "packages-16-east.internal.npmjs.com",
"tmp": "tmp/babel-code-frame-6.16.0.tgz_1475091527344_0.9727453696541488"
},
"_npmUser": {
"name": "hzoo",
"email": "hi@henryzoo.com"
},
"_npmVersion": "3.10.8",
"_phantomChildren": {},
"_requested": {
"raw": "babel-code-frame@^6.16.0",
"scope": null,
"escapedName": "babel-code-frame",
"name": "babel-code-frame",
"rawSpec": "^6.16.0",
"spec": ">=6.16.0 <7.0.0",
"type": "range"
},
"_requiredBy": [
"/babel-core",
"/babel-core/babel-traverse"
],
"_resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.16.0.tgz",
"_shasum": "f90e60da0862909d3ce098733b5d3987c97cb8de",
"_shrinkwrap": null,
"_spec": "babel-code-frame@^6.16.0",
"_where": "C:\\Users\\Lukas Obermann\\Projekte\\Cha5App\\code\\git\\node_modules\\babel-core",
"author": {
"name": "Sebastian McKenzie",
"email": "sebmck@gmail.com"
},
"dependencies": {
"chalk": "^1.1.0",
"esutils": "^2.0.2",
"js-tokens": "^2.0.0"
},
"description": "Generate errors that contain a code frame that point to source locations.",
"devDependencies": {},
"directories": {},
"dist": {
"shasum": "f90e60da0862909d3ce098733b5d3987c97cb8de",
"tarball": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.16.0.tgz"
},
"homepage": "https://babeljs.io/",
"license": "MIT",
"main": "lib/index.js",
"maintainers": [
{
"name": "amasad",
"email": "amjad.masad@gmail.com"
},
{
"name": "hzoo",
"email": "hi@henryzoo.com"
},
{
"name": "jmm",
"email": "npm-public@jessemccarthy.net"
},
{
"name": "loganfsmyth",
"email": "loganfsmyth@gmail.com"
},
{
"name": "sebmck",
"email": "sebmck@gmail.com"
},
{
"name": "thejameskyle",
"email": "me@thejameskyle.com"
}
],
"name": "babel-code-frame",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-code-frame"
},
"scripts": {},
"version": "6.16.0"
}
+64
View File
@@ -0,0 +1,64 @@
# babel-template
> Generate an AST from a string template.
In computer science, this is known as an implementation of quasiquotes.
## Install
```sh
$ npm install babel-template
```
## Usage
```js
import template from 'babel-template';
import generate from 'babel-generator';
import * as t from 'babel-types';
const buildRequire = template(`
var IMPORT_NAME = require(SOURCE);
`);
const ast = buildRequire({
IMPORT_NAME: t.identifier('myModule'),
SOURCE: t.stringLiteral('my-module')
});
console.log(generate(ast).code);
```
```js
var myModule = require('my-module');
```
## API
### `template(code, [opts])`
#### code
Type: `string`
#### options
`babel-template` accepts all of the options from [babylon], and specifies
some defaults of its own:
* `allowReturnOutsideFunction` is set to `true` by default.
* `allowSuperOutsideMethod` is set to `true` by default.
##### preserveComments
Type: `boolean`
Default: `false`
Set this to `true` to preserve any comments from the `code` parameter.
#### Return value
`babel-template` returns a `function` which is invoked with an optional object
of replacements. See the usage section for an example.
[babylon]: https://github.com/babel/babylon#options
+143
View File
@@ -0,0 +1,143 @@
"use strict";
exports.__esModule = true;
var _symbol = require("babel-runtime/core-js/symbol");
var _symbol2 = _interopRequireDefault(_symbol);
exports.default = function (code, opts) {
var stack = void 0;
try {
throw new Error();
} catch (error) {
if (error.stack) {
stack = error.stack.split("\n").slice(1).join("\n");
}
}
opts = (0, _assign2.default)({
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true,
preserveComments: false
}, opts);
var _getAst = function getAst() {
var ast = void 0;
try {
ast = babylon.parse(code, opts);
ast = _babelTraverse2.default.removeProperties(ast, { preserveComments: opts.preserveComments });
_babelTraverse2.default.cheap(ast, function (node) {
node[FROM_TEMPLATE] = true;
});
} catch (err) {
err.stack = err.stack + "from\n" + stack;
throw err;
}
_getAst = function getAst() {
return ast;
};
return ast;
};
return function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return useTemplate(_getAst(), args);
};
};
var _cloneDeep = require("lodash/cloneDeep");
var _cloneDeep2 = _interopRequireDefault(_cloneDeep);
var _assign = require("lodash/assign");
var _assign2 = _interopRequireDefault(_assign);
var _has = require("lodash/has");
var _has2 = _interopRequireDefault(_has);
var _babelTraverse = require("babel-traverse");
var _babelTraverse2 = _interopRequireDefault(_babelTraverse);
var _babylon = require("babylon");
var babylon = _interopRequireWildcard(_babylon);
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var FROM_TEMPLATE = "_fromTemplate";
var TEMPLATE_SKIP = (0, _symbol2.default)();
function useTemplate(ast, nodes) {
ast = (0, _cloneDeep2.default)(ast);
var _ast = ast;
var program = _ast.program;
if (nodes.length) {
(0, _babelTraverse2.default)(ast, templateVisitor, null, nodes);
}
if (program.body.length > 1) {
return program.body;
} else {
return program.body[0];
}
}
var templateVisitor = {
noScope: true,
enter: function enter(path, args) {
var node = path.node;
if (node[TEMPLATE_SKIP]) return path.skip();
if (t.isExpressionStatement(node)) {
node = node.expression;
}
var replacement = void 0;
if (t.isIdentifier(node) && node[FROM_TEMPLATE]) {
if ((0, _has2.default)(args[0], node.name)) {
replacement = args[0][node.name];
} else if (node.name[0] === "$") {
var i = +node.name.slice(1);
if (args[i]) replacement = args[i];
}
}
if (replacement === null) {
path.remove();
}
if (replacement) {
replacement[TEMPLATE_SKIP] = true;
path.replaceInline(replacement);
}
},
exit: function exit(_ref) {
var node = _ref.node;
if (!node.loc) _babelTraverse2.default.clearNode(node);
}
};
module.exports = exports["default"];
+104
View File
@@ -0,0 +1,104 @@
{
"_args": [
[
{
"raw": "babel-template@^6.16.0",
"scope": null,
"escapedName": "babel-template",
"name": "babel-template",
"rawSpec": "^6.16.0",
"spec": ">=6.16.0 <7.0.0",
"type": "range"
},
"C:\\Users\\Lukas Obermann\\Projekte\\Cha5App\\code\\git\\node_modules\\babel-core"
]
],
"_from": "babel-template@>=6.16.0 <7.0.0",
"_id": "babel-template@6.16.0",
"_inCache": true,
"_location": "/babel-core/babel-template",
"_nodeVersion": "5.11.1",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/babel-template-6.16.0.tgz_1475091544068_0.7295735867228359"
},
"_npmUser": {
"name": "hzoo",
"email": "hi@henryzoo.com"
},
"_npmVersion": "3.10.8",
"_phantomChildren": {},
"_requested": {
"raw": "babel-template@^6.16.0",
"scope": null,
"escapedName": "babel-template",
"name": "babel-template",
"rawSpec": "^6.16.0",
"spec": ">=6.16.0 <7.0.0",
"type": "range"
},
"_requiredBy": [
"/babel-core"
],
"_resolved": "https://registry.npmjs.org/babel-template/-/babel-template-6.16.0.tgz",
"_shasum": "e149dd1a9f03a35f817ddbc4d0481988e7ebc8ca",
"_shrinkwrap": null,
"_spec": "babel-template@^6.16.0",
"_where": "C:\\Users\\Lukas Obermann\\Projekte\\Cha5App\\code\\git\\node_modules\\babel-core",
"author": {
"name": "Sebastian McKenzie",
"email": "sebmck@gmail.com"
},
"dependencies": {
"babel-runtime": "^6.9.0",
"babel-traverse": "^6.16.0",
"babel-types": "^6.16.0",
"babylon": "^6.11.0",
"lodash": "^4.2.0"
},
"description": "Generate an AST from a string template.",
"devDependencies": {},
"directories": {},
"dist": {
"shasum": "e149dd1a9f03a35f817ddbc4d0481988e7ebc8ca",
"tarball": "https://registry.npmjs.org/babel-template/-/babel-template-6.16.0.tgz"
},
"homepage": "https://babeljs.io/",
"license": "MIT",
"main": "lib/index.js",
"maintainers": [
{
"name": "amasad",
"email": "amjad.masad@gmail.com"
},
{
"name": "hzoo",
"email": "hi@henryzoo.com"
},
{
"name": "jmm",
"email": "npm-public@jessemccarthy.net"
},
{
"name": "loganfsmyth",
"email": "loganfsmyth@gmail.com"
},
{
"name": "sebmck",
"email": "sebmck@gmail.com"
},
{
"name": "thejameskyle",
"email": "me@thejameskyle.com"
}
],
"name": "babel-template",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-template"
},
"scripts": {},
"version": "6.16.0"
}
+200
View File
@@ -0,0 +1,200 @@
"use strict";
exports.__esModule = true;
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _path2 = require("./path");
var _path3 = _interopRequireDefault(_path2);
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var testing = process.env.NODE_ENV === "test";
var TraversalContext = function () {
function TraversalContext(scope, opts, state, parentPath) {
(0, _classCallCheck3.default)(this, TraversalContext);
this.queue = null;
this.parentPath = parentPath;
this.scope = scope;
this.state = state;
this.opts = opts;
}
TraversalContext.prototype.shouldVisit = function shouldVisit(node) {
var opts = this.opts;
if (opts.enter || opts.exit) return true;
if (opts[node.type]) return true;
var keys = t.VISITOR_KEYS[node.type];
if (!keys || !keys.length) return false;
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var key = _ref;
if (node[key]) return true;
}
return false;
};
TraversalContext.prototype.create = function create(node, obj, key, listKey) {
return _path3.default.get({
parentPath: this.parentPath,
parent: node,
container: obj,
key: key,
listKey: listKey
});
};
TraversalContext.prototype.maybeQueue = function maybeQueue(path, notPriority) {
if (this.trap) {
throw new Error("Infinite cycle detected");
}
if (this.queue) {
if (notPriority) {
this.queue.push(path);
} else {
this.priorityQueue.push(path);
}
}
};
TraversalContext.prototype.visitMultiple = function visitMultiple(container, parent, listKey) {
if (container.length === 0) return false;
var queue = [];
for (var key = 0; key < container.length; key++) {
var node = container[key];
if (node && this.shouldVisit(node)) {
queue.push(this.create(parent, container, key, listKey));
}
}
return this.visitQueue(queue);
};
TraversalContext.prototype.visitSingle = function visitSingle(node, key) {
if (this.shouldVisit(node[key])) {
return this.visitQueue([this.create(node, node, key)]);
} else {
return false;
}
};
TraversalContext.prototype.visitQueue = function visitQueue(queue) {
this.queue = queue;
this.priorityQueue = [];
var visited = [];
var stop = false;
for (var _iterator2 = queue, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
var _ref2;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var path = _ref2;
path.resync();
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
path.pushContext(this);
}
if (path.key === null) continue;
if (testing && queue.length >= 10000) {
this.trap = true;
}
if (visited.indexOf(path.node) >= 0) continue;
visited.push(path.node);
if (path.visit()) {
stop = true;
break;
}
if (this.priorityQueue.length) {
stop = this.visitQueue(this.priorityQueue);
this.priorityQueue = [];
this.queue = queue;
if (stop) break;
}
}
for (var _iterator3 = queue, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
var _ref3;
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref3 = _iterator3[_i3++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref3 = _i3.value;
}
var _path = _ref3;
_path.popContext();
}
this.queue = null;
return stop;
};
TraversalContext.prototype.visit = function visit(node, key) {
var nodes = node[key];
if (!nodes) return false;
if (Array.isArray(nodes)) {
return this.visitMultiple(nodes, node, key);
} else {
return this.visitSingle(node, key);
}
};
return TraversalContext;
}();
exports.default = TraversalContext;
module.exports = exports["default"];
+162
View File
@@ -0,0 +1,162 @@
"use strict";
exports.__esModule = true;
exports.visitors = exports.Hub = exports.Scope = exports.NodePath = undefined;
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _path = require("./path");
Object.defineProperty(exports, "NodePath", {
enumerable: true,
get: function get() {
return _interopRequireDefault(_path).default;
}
});
var _scope = require("./scope");
Object.defineProperty(exports, "Scope", {
enumerable: true,
get: function get() {
return _interopRequireDefault(_scope).default;
}
});
var _hub = require("./hub");
Object.defineProperty(exports, "Hub", {
enumerable: true,
get: function get() {
return _interopRequireDefault(_hub).default;
}
});
exports.default = traverse;
var _context = require("./context");
var _context2 = _interopRequireDefault(_context);
var _visitors = require("./visitors");
var visitors = _interopRequireWildcard(_visitors);
var _babelMessages = require("babel-messages");
var messages = _interopRequireWildcard(_babelMessages);
var _includes = require("lodash/includes");
var _includes2 = _interopRequireDefault(_includes);
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _cache = require("./cache");
var cache = _interopRequireWildcard(_cache);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.visitors = visitors;
function traverse(parent, opts, scope, state, parentPath) {
if (!parent) return;
if (!opts) opts = {};
if (!opts.noScope && !scope) {
if (parent.type !== "Program" && parent.type !== "File") {
throw new Error(messages.get("traverseNeedsParent", parent.type));
}
}
visitors.explode(opts);
traverse.node(parent, opts, scope, state, parentPath);
}
traverse.visitors = visitors;
traverse.verify = visitors.verify;
traverse.explode = visitors.explode;
traverse.NodePath = require("./path");
traverse.Scope = require("./scope");
traverse.Hub = require("./hub");
traverse.cheap = function (node, enter) {
return t.traverseFast(node, enter);
};
traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
var keys = t.VISITOR_KEYS[node.type];
if (!keys) return;
var context = new _context2.default(scope, opts, state, parentPath);
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var key = _ref;
if (skipKeys && skipKeys[key]) continue;
if (context.visit(node, key)) return;
}
};
traverse.clearNode = function (node, opts) {
t.removeProperties(node, opts);
cache.path.delete(node);
};
traverse.removeProperties = function (tree, opts) {
t.traverseFast(tree, traverse.clearNode, opts);
return tree;
};
function hasBlacklistedType(path, state) {
if (path.node.type === state.type) {
state.has = true;
path.stop();
}
}
traverse.hasType = function (tree, scope, type, blacklistTypes) {
if ((0, _includes2.default)(blacklistTypes, tree.type)) return false;
if (tree.type === type) return true;
var state = {
has: false,
type: type
};
traverse(tree, {
blacklist: blacklistTypes,
enter: hasBlacklistedType
}, scope, state);
return state.has;
};
traverse.clearCache = function () {
cache.clear();
};
traverse.copyCache = function (source, destination) {
if (cache.path.has(source)) {
cache.path.set(destination, cache.path.get(source));
}
};
@@ -0,0 +1,226 @@
"use strict";
exports.__esModule = true;
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
exports.findParent = findParent;
exports.find = find;
exports.getFunctionParent = getFunctionParent;
exports.getStatementParent = getStatementParent;
exports.getEarliestCommonAncestorFrom = getEarliestCommonAncestorFrom;
exports.getDeepestCommonAncestorFrom = getDeepestCommonAncestorFrom;
exports.getAncestry = getAncestry;
exports.inType = inType;
exports.inShadow = inShadow;
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _index = require("./index");
var _index2 = _interopRequireDefault(_index);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function findParent(callback) {
var path = this;
while (path = path.parentPath) {
if (callback(path)) return path;
}
return null;
}
function find(callback) {
var path = this;
do {
if (callback(path)) return path;
} while (path = path.parentPath);
return null;
}
function getFunctionParent() {
return this.findParent(function (path) {
return path.isFunction() || path.isProgram();
});
}
function getStatementParent() {
var path = this;
do {
if (Array.isArray(path.container)) {
return path;
}
} while (path = path.parentPath);
}
function getEarliestCommonAncestorFrom(paths) {
return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {
var earliest = void 0;
var keys = t.VISITOR_KEYS[deepest.type];
for (var _iterator = ancestries, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var ancestry = _ref;
var path = ancestry[i + 1];
if (!earliest) {
earliest = path;
continue;
}
if (path.listKey && earliest.listKey === path.listKey) {
if (path.key < earliest.key) {
earliest = path;
continue;
}
}
var earliestKeyIndex = keys.indexOf(earliest.parentKey);
var currentKeyIndex = keys.indexOf(path.parentKey);
if (earliestKeyIndex > currentKeyIndex) {
earliest = path;
}
}
return earliest;
});
}
function getDeepestCommonAncestorFrom(paths, filter) {
var _this = this;
if (!paths.length) {
return this;
}
if (paths.length === 1) {
return paths[0];
}
var minDepth = Infinity;
var lastCommonIndex = void 0,
lastCommon = void 0;
var ancestries = paths.map(function (path) {
var ancestry = [];
do {
ancestry.unshift(path);
} while ((path = path.parentPath) && path !== _this);
if (ancestry.length < minDepth) {
minDepth = ancestry.length;
}
return ancestry;
});
var first = ancestries[0];
depthLoop: for (var i = 0; i < minDepth; i++) {
var shouldMatch = first[i];
for (var _iterator2 = ancestries, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
var _ref2;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var ancestry = _ref2;
if (ancestry[i] !== shouldMatch) {
break depthLoop;
}
}
lastCommonIndex = i;
lastCommon = shouldMatch;
}
if (lastCommon) {
if (filter) {
return filter(lastCommon, lastCommonIndex, ancestries);
} else {
return lastCommon;
}
} else {
throw new Error("Couldn't find intersection");
}
}
function getAncestry() {
var path = this;
var paths = [];
do {
paths.push(path);
} while (path = path.parentPath);
return paths;
}
function inType() {
var path = this;
while (path) {
for (var _iterator3 = arguments, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
var _ref3;
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref3 = _iterator3[_i3++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref3 = _i3.value;
}
var type = _ref3;
if (path.node.type === type) return true;
}
path = path.parentPath;
}
return false;
}
function inShadow(key) {
var parentFn = this.isFunction() ? this : this.findParent(function (p) {
return p.isFunction();
});
if (!parentFn) return;
if (parentFn.isFunctionExpression() || parentFn.isFunctionDeclaration()) {
var shadow = parentFn.node.shadow;
if (shadow && (!key || shadow[key] !== false)) {
return parentFn;
}
} else if (parentFn.isArrowFunctionExpression()) {
return parentFn;
}
return null;
}
@@ -0,0 +1,45 @@
"use strict";
exports.__esModule = true;
exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
exports.addComment = addComment;
exports.addComments = addComments;
function shareCommentsWithSiblings() {
var node = this.node;
if (!node) return;
var trailing = node.trailingComments;
var leading = node.leadingComments;
if (!trailing && !leading) return;
var prev = this.getSibling(this.key - 1);
var next = this.getSibling(this.key + 1);
if (!prev.node) prev = next;
if (!next.node) next = prev;
prev.addComments("trailing", leading);
next.addComments("leading", trailing);
}
function addComment(type, content, line) {
this.addComments(type, [{
type: line ? "CommentLine" : "CommentBlock",
value: content
}]);
}
function addComments(type, comments) {
if (!comments) return;
var node = this.node;
if (!node) return;
var key = type + "Comments";
if (node[key]) {
node[key] = node[key].concat(comments);
} else {
node[key] = comments;
}
}
+281
View File
@@ -0,0 +1,281 @@
"use strict";
exports.__esModule = true;
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
exports.call = call;
exports._call = _call;
exports.isBlacklisted = isBlacklisted;
exports.visit = visit;
exports.skip = skip;
exports.skipKey = skipKey;
exports.stop = stop;
exports.setScope = setScope;
exports.setContext = setContext;
exports.resync = resync;
exports._resyncParent = _resyncParent;
exports._resyncKey = _resyncKey;
exports._resyncList = _resyncList;
exports._resyncRemoved = _resyncRemoved;
exports.popContext = popContext;
exports.pushContext = pushContext;
exports.setup = setup;
exports.setKey = setKey;
exports.requeue = requeue;
exports._getQueueContexts = _getQueueContexts;
var _index = require("../index");
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function call(key) {
var opts = this.opts;
this.debug(function () {
return key;
});
if (this.node) {
if (this._call(opts[key])) return true;
}
if (this.node) {
return this._call(opts[this.node.type] && opts[this.node.type][key]);
}
return false;
}
function _call(fns) {
if (!fns) return false;
for (var _iterator = fns, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var fn = _ref;
if (!fn) continue;
var node = this.node;
if (!node) return true;
var ret = fn.call(this.state, this, this.state);
if (ret) throw new Error("Unexpected return value from visitor method " + fn);
if (this.node !== node) return true;
if (this.shouldStop || this.shouldSkip || this.removed) return true;
}
return false;
}
function isBlacklisted() {
var blacklist = this.opts.blacklist;
return blacklist && blacklist.indexOf(this.node.type) > -1;
}
function visit() {
if (!this.node) {
return false;
}
if (this.isBlacklisted()) {
return false;
}
if (this.opts.shouldSkip && this.opts.shouldSkip(this)) {
return false;
}
if (this.call("enter") || this.shouldSkip) {
this.debug(function () {
return "Skip...";
});
return this.shouldStop;
}
this.debug(function () {
return "Recursing into...";
});
_index2.default.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
this.call("exit");
return this.shouldStop;
}
function skip() {
this.shouldSkip = true;
}
function skipKey(key) {
this.skipKeys[key] = true;
}
function stop() {
this.shouldStop = true;
this.shouldSkip = true;
}
function setScope() {
if (this.opts && this.opts.noScope) return;
var target = this.context && this.context.scope;
if (!target) {
var path = this.parentPath;
while (path && !target) {
if (path.opts && path.opts.noScope) return;
target = path.scope;
path = path.parentPath;
}
}
this.scope = this.getScope(target);
if (this.scope) this.scope.init();
}
function setContext(context) {
this.shouldSkip = false;
this.shouldStop = false;
this.removed = false;
this.skipKeys = {};
if (context) {
this.context = context;
this.state = context.state;
this.opts = context.opts;
}
this.setScope();
return this;
}
function resync() {
if (this.removed) return;
this._resyncParent();
this._resyncList();
this._resyncKey();
}
function _resyncParent() {
if (this.parentPath) {
this.parent = this.parentPath.node;
}
}
function _resyncKey() {
if (!this.container) return;
if (this.node === this.container[this.key]) return;
if (Array.isArray(this.container)) {
for (var i = 0; i < this.container.length; i++) {
if (this.container[i] === this.node) {
return this.setKey(i);
}
}
} else {
for (var key in this.container) {
if (this.container[key] === this.node) {
return this.setKey(key);
}
}
}
this.key = null;
}
function _resyncList() {
if (!this.parent || !this.inList) return;
var newContainer = this.parent[this.listKey];
if (this.container === newContainer) return;
this.container = newContainer || null;
}
function _resyncRemoved() {
if (this.key == null || !this.container || this.container[this.key] !== this.node) {
this._markRemoved();
}
}
function popContext() {
this.contexts.pop();
this.setContext(this.contexts[this.contexts.length - 1]);
}
function pushContext(context) {
this.contexts.push(context);
this.setContext(context);
}
function setup(parentPath, container, listKey, key) {
this.inList = !!listKey;
this.listKey = listKey;
this.parentKey = listKey || key;
this.container = container;
this.parentPath = parentPath || this.parentPath;
this.setKey(key);
}
function setKey(key) {
this.key = key;
this.node = this.container[this.key];
this.type = this.node && this.node.type;
}
function requeue() {
var pathToQueue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this;
if (pathToQueue.removed) return;
var contexts = this.contexts;
for (var _iterator2 = contexts, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
var _ref2;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var context = _ref2;
context.maybeQueue(pathToQueue);
}
}
function _getQueueContexts() {
var path = this;
var contexts = this.contexts;
while (!contexts.length) {
path = path.parentPath;
contexts = path.contexts;
}
return contexts;
}
@@ -0,0 +1,47 @@
"use strict";
exports.__esModule = true;
exports.toComputedKey = toComputedKey;
exports.ensureBlock = ensureBlock;
exports.arrowFunctionToShadowed = arrowFunctionToShadowed;
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function toComputedKey() {
var node = this.node;
var key = void 0;
if (this.isMemberExpression()) {
key = node.property;
} else if (this.isProperty() || this.isMethod()) {
key = node.key;
} else {
throw new ReferenceError("todo");
}
if (!node.computed) {
if (t.isIdentifier(key)) key = t.stringLiteral(key.name);
}
return key;
}
function ensureBlock() {
return t.ensureBlock(this.node);
}
function arrowFunctionToShadowed() {
if (!this.isArrowFunctionExpression()) return;
this.ensureBlock();
var node = this.node;
node.expression = false;
node.type = "FunctionExpression";
node.shadow = node.shadow || true;
}
@@ -0,0 +1,394 @@
"use strict";
exports.__esModule = true;
var _typeof2 = require("babel-runtime/helpers/typeof");
var _typeof3 = _interopRequireDefault(_typeof2);
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _map = require("babel-runtime/core-js/map");
var _map2 = _interopRequireDefault(_map);
exports.evaluateTruthy = evaluateTruthy;
exports.evaluate = evaluate;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var VALID_CALLEES = ["String", "Number", "Math"];
var INVALID_METHODS = ["random"];
function evaluateTruthy() {
var res = this.evaluate();
if (res.confident) return !!res.value;
}
function evaluate() {
var confident = true;
var deoptPath = void 0;
var seen = new _map2.default();
function deopt(path) {
if (!confident) return;
deoptPath = path;
confident = false;
}
var value = evaluate(this);
if (!confident) value = undefined;
return {
confident: confident,
deopt: deoptPath,
value: value
};
function evaluate(path) {
var node = path.node;
if (seen.has(node)) {
var existing = seen.get(node);
if (existing.resolved) {
return existing.value;
} else {
deopt(path);
return;
}
} else {
var item = { resolved: false };
seen.set(node, item);
var val = _evaluate(path);
if (confident) {
item.resolved = true;
item.value = val;
}
return val;
}
}
function _evaluate(path) {
if (!confident) return;
var node = path.node;
if (path.isSequenceExpression()) {
var exprs = path.get("expressions");
return evaluate(exprs[exprs.length - 1]);
}
if (path.isStringLiteral() || path.isNumericLiteral() || path.isBooleanLiteral()) {
return node.value;
}
if (path.isNullLiteral()) {
return null;
}
if (path.isTemplateLiteral()) {
var str = "";
var i = 0;
var _exprs = path.get("expressions");
for (var _iterator = node.quasis, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var elem = _ref;
if (!confident) break;
str += elem.value.cooked;
var expr = _exprs[i++];
if (expr) str += String(evaluate(expr));
}
if (!confident) return;
return str;
}
if (path.isConditionalExpression()) {
var testResult = evaluate(path.get("test"));
if (!confident) return;
if (testResult) {
return evaluate(path.get("consequent"));
} else {
return evaluate(path.get("alternate"));
}
}
if (path.isExpressionWrapper()) {
return evaluate(path.get("expression"));
}
if (path.isMemberExpression() && !path.parentPath.isCallExpression({ callee: node })) {
var property = path.get("property");
var object = path.get("object");
if (object.isLiteral() && property.isIdentifier()) {
var _value = object.node.value;
var type = typeof _value === "undefined" ? "undefined" : (0, _typeof3.default)(_value);
if (type === "number" || type === "string") {
return _value[property.node.name];
}
}
}
if (path.isReferencedIdentifier()) {
var binding = path.scope.getBinding(node.name);
if (binding && binding.constantViolations.length > 0) {
return deopt(binding.path);
}
if (binding && binding.hasValue) {
return binding.value;
} else {
if (node.name === "undefined") {
return undefined;
} else if (node.name === "Infinity") {
return Infinity;
} else if (node.name === "NaN") {
return NaN;
}
var resolved = path.resolve();
if (resolved === path) {
return deopt(path);
} else {
return evaluate(resolved);
}
}
}
if (path.isUnaryExpression({ prefix: true })) {
if (node.operator === "void") {
return undefined;
}
var argument = path.get("argument");
if (node.operator === "typeof" && (argument.isFunction() || argument.isClass())) {
return "function";
}
var arg = evaluate(argument);
if (!confident) return;
switch (node.operator) {
case "!":
return !arg;
case "+":
return +arg;
case "-":
return -arg;
case "~":
return ~arg;
case "typeof":
return typeof arg === "undefined" ? "undefined" : (0, _typeof3.default)(arg);
}
}
if (path.isArrayExpression()) {
var arr = [];
var elems = path.get("elements");
for (var _iterator2 = elems, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
var _ref2;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var _elem = _ref2;
_elem = _elem.evaluate();
if (_elem.confident) {
arr.push(_elem.value);
} else {
return deopt(_elem);
}
}
return arr;
}
if (path.isObjectExpression()) {
var obj = {};
var props = path.get("properties");
for (var _iterator3 = props, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
var _ref3;
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref3 = _iterator3[_i3++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref3 = _i3.value;
}
var prop = _ref3;
if (prop.isObjectMethod() || prop.isSpreadProperty()) {
return deopt(prop);
}
var keyPath = prop.get("key");
var key = keyPath;
if (prop.node.computed) {
key = key.evaluate();
if (!key.confident) {
return deopt(keyPath);
}
key = key.value;
} else if (key.isIdentifier()) {
key = key.node.name;
} else {
key = key.node.value;
}
var valuePath = prop.get("value");
var _value2 = valuePath.evaluate();
if (!_value2.confident) {
return deopt(valuePath);
}
_value2 = _value2.value;
obj[key] = _value2;
}
return obj;
}
if (path.isLogicalExpression()) {
var wasConfident = confident;
var left = evaluate(path.get("left"));
var leftConfident = confident;
confident = wasConfident;
var right = evaluate(path.get("right"));
var rightConfident = confident;
confident = leftConfident && rightConfident;
switch (node.operator) {
case "||":
if (left && leftConfident) {
confident = true;
return left;
}
if (!confident) return;
return left || right;
case "&&":
if (!left && leftConfident || !right && rightConfident) {
confident = true;
}
if (!confident) return;
return left && right;
}
}
if (path.isBinaryExpression()) {
var _left = evaluate(path.get("left"));
if (!confident) return;
var _right = evaluate(path.get("right"));
if (!confident) return;
switch (node.operator) {
case "-":
return _left - _right;
case "+":
return _left + _right;
case "/":
return _left / _right;
case "*":
return _left * _right;
case "%":
return _left % _right;
case "**":
return Math.pow(_left, _right);
case "<":
return _left < _right;
case ">":
return _left > _right;
case "<=":
return _left <= _right;
case ">=":
return _left >= _right;
case "==":
return _left == _right;
case "!=":
return _left != _right;
case "===":
return _left === _right;
case "!==":
return _left !== _right;
case "|":
return _left | _right;
case "&":
return _left & _right;
case "^":
return _left ^ _right;
case "<<":
return _left << _right;
case ">>":
return _left >> _right;
case ">>>":
return _left >>> _right;
}
}
if (path.isCallExpression()) {
var callee = path.get("callee");
var context = void 0;
var func = void 0;
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) && VALID_CALLEES.indexOf(callee.node.name) >= 0) {
func = global[node.callee.name];
}
if (callee.isMemberExpression()) {
var _object = callee.get("object");
var _property = callee.get("property");
if (_object.isIdentifier() && _property.isIdentifier() && VALID_CALLEES.indexOf(_object.node.name) >= 0 && INVALID_METHODS.indexOf(_property.node.name) < 0) {
context = global[_object.node.name];
func = context[_property.node.name];
}
if (_object.isLiteral() && _property.isIdentifier()) {
var _type = (0, _typeof3.default)(_object.node.value);
if (_type === "string" || _type === "number") {
context = _object.node.value;
func = context[_property.node.name];
}
}
}
if (func) {
var args = path.get("arguments").map(evaluate);
if (!confident) return;
return func.apply(context, args);
}
}
deopt(path);
}
}
+165
View File
@@ -0,0 +1,165 @@
"use strict";
exports.__esModule = true;
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
exports.getStatementParent = getStatementParent;
exports.getOpposite = getOpposite;
exports.getCompletionRecords = getCompletionRecords;
exports.getSibling = getSibling;
exports.get = get;
exports._getKey = _getKey;
exports._getPattern = _getPattern;
exports.getBindingIdentifiers = getBindingIdentifiers;
exports.getOuterBindingIdentifiers = getOuterBindingIdentifiers;
var _index = require("./index");
var _index2 = _interopRequireDefault(_index);
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function getStatementParent() {
var path = this;
do {
if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
break;
} else {
path = path.parentPath;
}
} while (path);
if (path && (path.isProgram() || path.isFile())) {
throw new Error("File/Program node, we can't possibly find a statement parent to this");
}
return path;
}
function getOpposite() {
if (this.key === "left") {
return this.getSibling("right");
} else if (this.key === "right") {
return this.getSibling("left");
}
}
function getCompletionRecords() {
var paths = [];
var add = function add(path) {
if (path) paths = paths.concat(path.getCompletionRecords());
};
if (this.isIfStatement()) {
add(this.get("consequent"));
add(this.get("alternate"));
} else if (this.isDoExpression() || this.isFor() || this.isWhile()) {
add(this.get("body"));
} else if (this.isProgram() || this.isBlockStatement()) {
add(this.get("body").pop());
} else if (this.isFunction()) {
return this.get("body").getCompletionRecords();
} else if (this.isTryStatement()) {
add(this.get("block"));
add(this.get("handler"));
add(this.get("finalizer"));
} else {
paths.push(this);
}
return paths;
}
function getSibling(key) {
return _index2.default.get({
parentPath: this.parentPath,
parent: this.parent,
container: this.container,
listKey: this.listKey,
key: key
});
}
function get(key, context) {
if (context === true) context = this.context;
var parts = key.split(".");
if (parts.length === 1) {
return this._getKey(key, context);
} else {
return this._getPattern(parts, context);
}
}
function _getKey(key, context) {
var _this = this;
var node = this.node;
var container = node[key];
if (Array.isArray(container)) {
return container.map(function (_, i) {
return _index2.default.get({
listKey: key,
parentPath: _this,
parent: node,
container: container,
key: i
}).setContext(context);
});
} else {
return _index2.default.get({
parentPath: this,
parent: node,
container: node,
key: key
}).setContext(context);
}
}
function _getPattern(parts, context) {
var path = this;
for (var _iterator = parts, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var part = _ref;
if (part === ".") {
path = path.parentPath;
} else {
if (Array.isArray(path)) {
path = path[part];
} else {
path = path.get(part, context);
}
}
}
return path;
}
function getBindingIdentifiers(duplicates) {
return t.getBindingIdentifiers(this.node, duplicates);
}
function getOuterBindingIdentifiers(duplicates) {
return t.getOuterBindingIdentifiers(this.node, duplicates);
}

Some files were not shown because too many files have changed in this diff Show More