Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -109,6 +109,7 @@
"intl-messageformat-parser": "^6.1.0",
"isomorphic-fetch": "^2.2.1",
"java-parser": "^2.0.1",
"jinx-rust": "^0.1.4",
"jscodeshift": "^0.11.0",
"json-stringify-safe": "^5.0.1",
"json-to-ast": "^2.1.0",
Expand Down
108 changes: 108 additions & 0 deletions website/src/parsers/rust/jinx-rust.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import defaultParserInterface from '../utils/defaultParserInterface';
import pkg from 'jinx-rust/package.json';

const id = 'jinx-rust';

function is_Circular(data, key) {
return key === 'src';
}

/** @type {typeof defaultParserInterface} */
export default {
...defaultParserInterface,

id,
displayName: id,
version: pkg.version,
homepage: `https://www.github.com/jinxdash/jinx-rust/`,

_ignoredProperties: new Set(['toJSON']),

locationProps: new Set(['loc']),
typeProps: new Set(['type', 'get type()', 'nodeType']),

loadParser(callback) {
require(['jinx-rust'], callback);
},

parse(module, code, options) {
return module.rs.parseFile(code, { filepath: 'undefined.rs' });
},

getNodeName(node) {
return is_object(node)
? 'type' in node
? node.type
: node.constructor.name
: null;
},

*forEachProperty(data) {
if (!is_object(data)) return;

if (Array.isArray(data)) {
for (var key in data)
yield {
key,
value: data[key],
computed: false,
};
} else {
const descriptors = getAllPropertyDescriptors(data);
const keys = Object.keys(descriptors);

const typeIndex =
keys.length > 2 && keys[0] === 'nodeType' && keys[1] === 'loc'
? keys.indexOf('type')
: -1;

if (typeIndex !== -1) {
keys.splice(typeIndex, 1);
yield { key: 'get type()', value: () => data.type };
}

for (var key of keys) {
if (this._ignoredProperties.has(key)) continue;
var descriptor = descriptors[key];
var value = data[key];
yield {
key: 'get' in descriptor ? 'get ' + key + '()' : key,
value: is_Circular(data, key)
? `[Circular] ${this.getNodeName(value)}`
: typeof value === 'function'
? value.bind(data)
: 'get' in descriptor
? () => value
: value,
};
}
}
},

nodeToRange(node) {
return is_object(node) && 'loc' in node ? [node.loc[0], node.loc[1]] : null;
},
};

function is_object(data) {
return typeof data === 'object' && null !== data;
}

/** @returns {{ [key: string]: PropertyDescriptor }} */
function getAllPropertyDescriptors(data) {
const descriptors = Object.create(null);
for (var key of Object.getOwnPropertyNames(data)) {
descriptors[key] = Object.getOwnPropertyDescriptor(data, key);
}
var p1 = Object.getPrototypeOf(data);
if (null !== p1)
while (null !== Object.getPrototypeOf(p1)) {
for (var key of Object.getOwnPropertyNames(p1)) {
if ('constructor' !== key && !(key in descriptors)) {
descriptors[key] = Object.getOwnPropertyDescriptor(p1, key);
}
}
p1 = Object.getPrototypeOf(p1);
}
return descriptors;
}
1 change: 1 addition & 0 deletions website/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ module.exports = Object.assign({
path.join(__dirname, 'node_modules', 'tslint'),
path.join(__dirname, 'node_modules', 'tslib'),
path.join(__dirname, 'node_modules', 'svelte'),
path.join(__dirname, 'node_modules', 'jinx-rust'),
path.join(__dirname, 'src'),
],
loader: 'babel-loader',
Expand Down
5 changes: 5 additions & 0 deletions website/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6923,6 +6923,11 @@ jest-worker@^25.1.0:
merge-stream "^2.0.0"
supports-color "^7.0.0"

jinx-rust@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/jinx-rust/-/jinx-rust-0.1.4.tgz#26203096050f09c1996221c12b0bbe274ace8900"
integrity sha512-Tp4TewXfwFi/OVlDz/uz5tRx11cPvgzD4nFgt+DtLCuICCGiQr8M8TY9xqtKQGHXB7ho115Zf3sxOYjJO9kwcA==

js-tokens@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-1.0.1.tgz#cc435a5c8b94ad15acb7983140fc80182c89aeae"
Expand Down