Create "addsMap" without unneeded indexes

This commit is contained in:
igor 2018-02-05 11:18:17 +02:00
parent 3428d9e6b3
commit 4eedfde88c
2 changed files with 18 additions and 39 deletions

View File

@ -3,168 +3,140 @@
exports[`inject-decorator positive calculates "adds" map 1`] = ` exports[`inject-decorator positive calculates "adds" map 1`] = `
Object { Object {
"Addons|Info.Decorator@Use Info as story decorator": Object { "Addons|Info.Decorator@Use Info as story decorator": Object {
"end": 4570,
"endLoc": Object { "endLoc": Object {
"col": 74, "col": 74,
"line": 137, "line": 137,
}, },
"start": 4504,
"startLoc": Object { "startLoc": Object {
"col": 8, "col": 8,
"line": 137, "line": 137,
}, },
}, },
"Addons|Info.GitHub issues@#1814": Object { "Addons|Info.GitHub issues@#1814": Object {
"end": 4978,
"endLoc": Object { "endLoc": Object {
"col": 5, "col": 5,
"line": 152, "line": 152,
}, },
"start": 4838,
"startLoc": Object { "startLoc": Object {
"col": 3, "col": 3,
"line": 146, "line": 146,
}, },
}, },
"Addons|Info.Markdown@Displays Markdown in description": Object { "Addons|Info.Markdown@Displays Markdown in description": Object {
"end": 1827,
"endLoc": Object { "endLoc": Object {
"col": 97, "col": 97,
"line": 44, "line": 44,
}, },
"start": 1694,
"startLoc": Object { "startLoc": Object {
"col": 3, "col": 3,
"line": 43, "line": 43,
}, },
}, },
"Addons|Info.Options.TableComponent@Use a custom component for the table": Object { "Addons|Info.Options.TableComponent@Use a custom component for the table": Object {
"end": 4311,
"endLoc": Object { "endLoc": Object {
"col": 42, "col": 42,
"line": 130, "line": 130,
}, },
"start": 4194,
"startLoc": Object { "startLoc": Object {
"col": 3, "col": 3,
"line": 127, "line": 127,
}, },
}, },
"Addons|Info.Options.header@Shows or hides Info Addon header": Object { "Addons|Info.Options.header@Shows or hides Info Addon header": Object {
"end": 2423,
"endLoc": Object { "endLoc": Object {
"col": 42, "col": 42,
"line": 60, "line": 60,
}, },
"start": 2193,
"startLoc": Object { "startLoc": Object {
"col": 3, "col": 3,
"line": 56, "line": 56,
}, },
}, },
"Addons|Info.Options.inline@Inlines component inside story": Object { "Addons|Info.Options.inline@Inlines component inside story": Object {
"end": 2129,
"endLoc": Object { "endLoc": Object {
"col": 42, "col": 42,
"line": 52, "line": 52,
}, },
"start": 1891,
"startLoc": Object { "startLoc": Object {
"col": 3, "col": 3,
"line": 48, "line": 48,
}, },
}, },
"Addons|Info.Options.propTables@Shows additional component prop tables": Object { "Addons|Info.Options.propTables@Shows additional component prop tables": Object {
"end": 2994,
"endLoc": Object { "endLoc": Object {
"col": 42, "col": 42,
"line": 76, "line": 76,
}, },
"start": 2770,
"startLoc": Object { "startLoc": Object {
"col": 3, "col": 3,
"line": 72, "line": 72,
}, },
}, },
"Addons|Info.Options.propTablesExclude@Exclude component from prop tables": Object { "Addons|Info.Options.propTablesExclude@Exclude component from prop tables": Object {
"end": 3384,
"endLoc": Object { "endLoc": Object {
"col": 5, "col": 5,
"line": 89, "line": 89,
}, },
"start": 3069,
"startLoc": Object { "startLoc": Object {
"col": 3, "col": 3,
"line": 80, "line": 80,
}, },
}, },
"Addons|Info.Options.source@Shows or hides Info Addon source": Object { "Addons|Info.Options.source@Shows or hides Info Addon source": Object {
"end": 2702,
"endLoc": Object { "endLoc": Object {
"col": 42, "col": 42,
"line": 68, "line": 68,
}, },
"start": 2487,
"startLoc": Object { "startLoc": Object {
"col": 3, "col": 3,
"line": 64, "line": 64,
}, },
}, },
"Addons|Info.Options.styles@Extend info styles with an object": Object { "Addons|Info.Options.styles@Extend info styles with an object": Object {
"end": 3768,
"endLoc": Object { "endLoc": Object {
"col": 44, "col": 44,
"line": 108, "line": 108,
}, },
"start": 3454,
"startLoc": Object { "startLoc": Object {
"col": 5, "col": 5,
"line": 94, "line": 94,
}, },
}, },
"Addons|Info.Options.styles@Full control over styles using a function": Object { "Addons|Info.Options.styles@Full control over styles using a function": Object {
"end": 4120,
"endLoc": Object { "endLoc": Object {
"col": 44, "col": 44,
"line": 123, "line": 123,
}, },
"start": 3788,
"startLoc": Object { "startLoc": Object {
"col": 5, "col": 5,
"line": 111, "line": 111,
}, },
}, },
"Addons|Info.React Docgen@Comments from Flow declarations": Object { "Addons|Info.React Docgen@Comments from Flow declarations": Object {
"end": 1054,
"endLoc": Object { "endLoc": Object {
"col": 86, "col": 86,
"line": 22, "line": 22,
}, },
"start": 773,
"startLoc": Object { "startLoc": Object {
"col": 5, "col": 5,
"line": 19, "line": 19,
}, },
}, },
"Addons|Info.React Docgen@Comments from PropType declarations": Object { "Addons|Info.React Docgen@Comments from PropType declarations": Object {
"end": 753,
"endLoc": Object { "endLoc": Object {
"col": 80, "col": 80,
"line": 16, "line": 16,
}, },
"start": 470,
"startLoc": Object { "startLoc": Object {
"col": 5, "col": 5,
"line": 13, "line": 13,
}, },
}, },
"Addons|Info.React Docgen@Comments from component declaration": Object { "Addons|Info.React Docgen@Comments from component declaration": Object {
"end": 1348,
"endLoc": Object { "endLoc": Object {
"col": 71, "col": 71,
"line": 28, "line": 28,
}, },
"start": 1074,
"startLoc": Object { "startLoc": Object {
"col": 5, "col": 5,
"line": 25, "line": 25,

View File

@ -16,15 +16,23 @@ const acornConfig = {
function calculateLocations(source, adds) { function calculateLocations(source, adds) {
const addsKeys = Object.keys(adds); const addsKeys = Object.keys(adds);
if (addsKeys.length > 0) { if (!addsKeys.length) {
const lineColumnFinder = lineColumn(source); return {};
Object.keys(adds).forEach(key => {
const value = adds[key];
value.startLoc = lineColumnFinder.fromIndex(value.start);
value.endLoc = lineColumnFinder.fromIndex(value.end);
});
} }
const lineColumnFinder = lineColumn(source);
return addsKeys.reduce((map, key) => {
const value = adds[key];
// eslint-disable-next-line no-param-reassign
map[key] = {
startLoc: lineColumnFinder.fromIndex(value.start),
endLoc: lineColumnFinder.fromIndex(value.end),
};
return map;
}, {});
} }
function inject(source, decorator) { function inject(source, decorator) {
@ -47,14 +55,13 @@ function inject(source, decorator) {
}, },
}); });
calculateLocations(source, adds); const addsMap = calculateLocations(source, adds);
const newSource = parts.join(decorator); const newSource = parts.join(decorator);
return { return {
changed: lastIndex > 0, changed: lastIndex > 0,
source: newSource, source: newSource,
addsMap: adds, addsMap,
}; };
} }