fix(javascript): do not attach to block if it's not behind right func paren (#5435)

This commit is contained in:
Ika authored and GitHub committed 2018-11-11 00:10:19 +08:00
1 parent 182a92eb28
commit e0f74cb94d
4 files changed
+48 -4

No files matched your search

+9 -2
View File
@@ -196,9 +196,8 @@ function isNextLineEmpty(text, node, locEnd) {
return isNextLineEmptyAfterIndex(text, locEnd(node));
}
function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
let oldIdx = null;
let idx = locEnd(node);
while (idx !== oldIdx) {
oldIdx = idx;
idx = skipSpaces(text, idx);
@@ -209,6 +208,13 @@ function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
return idx;
}
function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(
text,
locEnd(node)
);
}
function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
return text.charAt(
getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
@@ -679,6 +685,7 @@ module.exports = {
getParentExportDeclaration,
getPenultimate,
getLast,
getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
getNextNonSpaceNonCommentCharacterIndex,
getNextNonSpaceNonCommentCharacter,
skip,
+20 -2
View File
@@ -630,8 +630,26 @@ function handleLastFunctionArgComments(
followingNode &&
followingNode.type === "BlockStatement"
) {
addBlockStatementFirstComment(followingNode, comment);
return true;
const functionParamRightParenIndex = (() => {
if (enclosingNode.params.length !== 0) {
return privateUtil.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(
text,
options.locEnd(privateUtil.getLast(enclosingNode.params))
);
}
const functionParamLeftParenIndex = privateUtil.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(
text,
options.locEnd(enclosingNode.id)
);
return privateUtil.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(
text,
functionParamLeftParenIndex + 1
);
})();
if (options.locStart(comment) > functionParamRightParenIndex) {
addBlockStatementFirstComment(followingNode, comment);
return true;
}
}
return false;
@@ -26,3 +26,17 @@ class Component extends React.Component /*:: <Props, State> */ {
}
`;
exports[`functions.js - babylon-verify 1`] = `
export function updateStoreFromURL(
store /*: Store*/,
{search, hash} /*: {search: string, hash: string}*/
) {}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export function updateStoreFromURL(
store /*: Store*/,
{ search, hash } /*: {search: string, hash: string}*/
) {}
`;
@@ -0,0 +1,5 @@
export function updateStoreFromURL(
store /*: Store*/,
{search, hash} /*: {search: string, hash: string}*/
) {}