Skip to content

Commit

Permalink
Use callback
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Feb 9, 2021
1 parent 6739d43 commit ededec2
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -210,7 +210,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
accessibility?: N.Accessibility,
},
allowedModifiers: TsModifier[],
disallowedModifiers?: TsModifier[],
callback?: (startPos: number, modifer: TsModifier) => void,
): void {
for (;;) {
const startPos = this.state.start;
Expand All @@ -231,8 +231,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
modified[modifier] = true;
}

if (disallowedModifiers && disallowedModifiers.includes(modifier)) {
this.raise(startPos, TSErrors.InvalidModifierOnTypeMember, modifier);
if (callback) {
callback(startPos, modifier);
}
}
}
Expand Down Expand Up @@ -584,6 +584,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
}

const denyModifiers = [
"declare",
"abstract",
"private",
"protected",
"public",
"static",
];
this.tsParseModifiers(
node,
[
Expand All @@ -595,7 +603,15 @@ export default (superClass: Class<Parser>): Class<Parser> =>
"public",
"static",
],
["declare", "abstract", "private", "protected", "public", "static"],
(startPos, modifier) => {
if (denyModifiers.includes(modifier)) {
this.raise(
startPos,
TSErrors.InvalidModifierOnTypeMember,
modifier,
);
}
},
);

const idx = this.tsTryParseIndexSignature(node);
Expand Down

0 comments on commit ededec2

Please sign in to comment.