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

feat: wxml parser #642

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@typescript-eslint/parser": "^5.0.0",
"@vue/compiler-dom": "^3.0.0-rc.10",
"@webassemblyjs/wast-parser": "^1.9.0",
"@wxml/parser": "^0.4.0",
"acorn": "^8.3.0",
"acorn-jsx": "^5.3.1",
"acorn-loose": "^8.1.0",
Expand Down
16 changes: 16 additions & 0 deletions website/src/parsers/wxml/codeExample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<view class="search-contianer">
<view class="search" style="height:{{navHeight}}px;padding-top:{{navTop}}px">
<view class="search-title" src="../../images/actLogo/ytlogo.png">
{{mallName}}
</view>
<input
placeholder-class="search-placeholder"
type="text"
placeholder="please enter keyword for search"
disabled
value="{{name}}"
bindinput="bindinput"
bindtap="goSearch">
</input>
</view>
</view>
4 changes: 4 additions & 0 deletions website/src/parsers/wxml/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const id = 'wxml';
export const displayName = 'WXML';
export const mimeTypes = [];
export const fileExtension = 'wxml';
41 changes: 41 additions & 0 deletions website/src/parsers/wxml/wxml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { VERSION, parse } from '@wxml/parser';
import defaultParserInterface from '../utils/defaultParserInterface';

const ID = 'wxml';

export default {
...defaultParserInterface,

id: ID,
displayName: ID,
homepage: 'https://github.com/wxmlfile/wxml-parser',
version: VERSION,
locationProps: new Set(['start', 'end', 'loc']),

async loadParser(callback) {
require(['@wxml/parser'], callback);
},

parse(parser, code) {
try {
return parser.parse(code);
} catch (message) {
// AST Explorer expects the thrown error to be an object, not a string.
throw new SyntaxError(message);
}
},
opensByDefault(node, key) {
return key === 'children';
},

getNodeName(node) {
return node.type;
},

nodeToRange(node) {
if (typeof node.start === 'number') {
return [node.start, node.end];
}
return node.range;
},
};
5 changes: 5 additions & 0 deletions website/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,11 @@
"@webassemblyjs/wast-parser" "1.9.0"
"@xtuc/long" "4.2.2"

"@wxml/parser@^0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@wxml/parser/-/parser-0.4.0.tgz#14c9ad4834a5c5b6c0e18126da79f82ec8b0fa97"
integrity sha512-pS0OPyKzCOhCPGlcfO9IDLZbqH4485bPdGDqaa+hYnI+cY/OW+GN4J88XpfdzM8wXJcJShFZy5F6MTUr2rysXg==

"@xtuc/ieee754@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@xtuc/ieee754/-/ieee754-1.2.0.tgz#eef014a3145ae477a1cbc00cd1e552336dceb790"
Expand Down