Skip to content

Commit

Permalink
fix: material-help
Browse files Browse the repository at this point in the history
  • Loading branch information
GiveMe-A-Name committed Aug 16, 2021
1 parent 50f2664 commit d7e4a90
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default (doc: vscode.TextDocument): Set<string> => {
try {
const ast = parse(documentText, {
sourceType: 'module',
plugins: getBabelParserPlugins('jsx'),
plugins: getBabelParserPlugins('ts'),
errorRecovery: true,
});
traverse(ast, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import getBabelParserPlugins from '../utils/getBabelParserPlugins';
function isCursorInObjectExpression(callExpression: CallExpression, cursorPosition: number): boolean {
const callArguments = callExpression.arguments;
const node = callArguments?.[0];

return isObjectExpression(node) && (node.start < cursorPosition && cursorPosition < node.end);
return isObjectExpression(node) && (<number>node.start < cursorPosition && cursorPosition < <number>node.end);
}

function conditionOfCompletion(callExpression: CallExpression, cursorPosition: number): boolean {
Expand All @@ -31,7 +30,7 @@ function getOriginCurrentCallExpress(
try {
const ast = parse(code, {
sourceType: 'module',
plugins: getBabelParserPlugins('jsx'),
plugins: getBabelParserPlugins('ts'),
});
traverse(ast, {
CallExpression(path: NodePath<CallExpression>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default (doc: vscode.TextDocument, location: vscode.Location): string[] =
try {
const ast = parse(definitionsCode, {
sourceType: 'module',
plugins: getBabelParserPlugins('jsx'),
plugins: getBabelParserPlugins('js'),
});
if (checkIsCapitalizeWord(originSelectionCode) && checkIsJsxComponent(ast)) {
return getJsxPropKeysFromAst(ast);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default (code: string, uri: vscode.Uri): string => {
try {
const ast = parse(code, {
sourceType: 'module',
plugins: getBabelParserPlugins('jsx'),
plugins: getBabelParserPlugins('js'),
errorRecovery: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function getPropKeysFromCode(componentPath: string): string[] {
try {
const ast = parse(fs.readFileSync(componentPath, 'utf-8'), {
sourceType: 'module',
plugins: getBabelParserPlugins('jsx'),
plugins: getBabelParserPlugins('js'),
});

if (ast) {
Expand Down
4 changes: 2 additions & 2 deletions extensions/material-helper/src/utils/getBabelParserPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ParserPlugin } from '@babel/parser';

export default function getBabelParserPlugins(language: string): ParserPlugin[] {
export default function getBabelParserPlugins(language: 'ts' | 'js'): ParserPlugin[] {
const plugins: ParserPlugin[] = [
'jsx',
'doExpressions',
'objectRestSpread',
'decorators-legacy',
Expand All @@ -18,7 +19,6 @@ export default function getBabelParserPlugins(language: string): ParserPlugin[]
plugins.unshift('typescript');
} else {
plugins.unshift('flow');
plugins.unshift('jsx');
}

return plugins;
Expand Down
2 changes: 1 addition & 1 deletion extensions/material-helper/src/utils/getComponentSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function getComponentSource(
) {
const ast = parser.parse(documentText, {
sourceType: 'module',
plugins: getBabelParserPlugins('jsx'),
plugins: getBabelParserPlugins('ts'),
});

const result = { source: '', importedComponent: '' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function getCurrentJsxElement(
// https://babeljs.io/docs/en/babel-parser
const ast = parse(documentText, {
sourceType: 'module',
plugins: getBabelParserPlugins('jsx'),
plugins: getBabelParserPlugins('ts'),
});

if (ast) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/material-helper/src/utils/getJsxElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function getJsxElements(
// https://babeljs.io/docs/en/babel-parser
const ast = parse(documentText, {
sourceType: 'module',
plugins: getBabelParserPlugins('jsx'),
plugins: getBabelParserPlugins('ts'),
});

if (ast) {
Expand Down

0 comments on commit d7e4a90

Please sign in to comment.