Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: material-help #946

Merged
merged 3 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extensions/material-helper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Change Log
## 1.0.10
- fix: the babel plugin's flow will cause error, when babel parse typescript files.

## 1.0.9

Expand Down
2 changes: 1 addition & 1 deletion extensions/material-helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Component Helper",
"description": "Easily use Component in React/Vue/Rax.",
"publisher": "iceworks-team",
"version": "1.0.9",
"version": "1.0.10",
"main": "./build/extension.js",
"engines": {
"vscode": "^1.41.0"
Expand Down
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