Skip to content

Commit

Permalink
Initial support for swc
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed May 12, 2021
1 parent a565b32 commit bb113f9
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@glimmer/syntax": "^0.73.1",
"@humanwhocodes/momoa": "^1.0.0",
"@mdx-js/mdx": "^1.5.8",
"@swc/wasm-web": "^1.2.57",
"@typescript-eslint/parser": "^4.1.0",
"@vue/compiler-dom": "^3.0.0-rc.10",
"@webassemblyjs/wast-parser": "^1.9.0",
Expand Down
59 changes: 59 additions & 0 deletions website/src/parsers/js/swc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import defaultParserInterface from './utils/defaultESTreeParserInterface';
import pkg from '@swc/wasm-web/package.json';

const ID = '@swc/wasm-web';
export const defaultOptions = {
syntax: 'ecmascript',
tsx: false,
jsx: false,
dynamicImport: false,
};
export const parserSettingsConfiguration = {
fields: [
['syntax', ['ecmascript', 'typescript']],
'tsx',
'jsx',
'dynamicImport',
],
};

export default {
...defaultParserInterface,

id: ID,
displayName: ID,
version: pkg.version,
homepage: pkg.homepage || 'https://swc.rs/',
locationProps: new Set(['span']),

opensByDefault(node, key) {
return (
(Boolean(node) && node.type === 'Module') ||
key === 'body' ||
key === 'elements' || // array literals
key === 'declarations' || // variable declaration
key === 'expression' // expression statements
);
},

loadParser(callback) {
require(['@swc/wasm-web'], callback);
},

parse(swc, code, options) {
return swc.parseSync(code, options);
},

getDefaultOptions() {
return defaultOptions;
},

_getSettingsConfiguration() {
return parserSettingsConfiguration;
},

nodeToRange(node) {
// TODO
return node.range;
},
};
5 changes: 5 additions & 0 deletions website/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,11 @@
resolved "https://registry.yarnpkg.com/@simple-dom/interface/-/interface-1.4.0.tgz#e8feea579232017f89b0138e2726facda6fbb71f"
integrity sha512-l5qumKFWU0S+4ZzMaLXFU8tQZsicHEMEyAxI5kDFGhJsRqDwe0a7/iPA/GdxlGyDKseQQAgIz5kzU7eXTrlSpA==

"@swc/wasm-web@^1.2.57":
version "1.2.57"
resolved "https://registry.yarnpkg.com/@swc/wasm-web/-/wasm-web-1.2.57.tgz#547e9d64d82f279947021665633d505863d68494"
integrity sha512-Z5VrTsrvUafYhdgpHYoWUjKdVzPpAxgcRd7n0xWgCICCqrhQw/M6rIhAhItb865U66ChqBPfhn7fHezwOL8XJA==

"@types/color-name@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
Expand Down

0 comments on commit bb113f9

Please sign in to comment.