Skip to content

Commit

Permalink
Merge pull request #13 from fink-lang/latest-larix
Browse files Browse the repository at this point in the history
feat(object): support calculated props
  • Loading branch information
kollhof authored Mar 1, 2020
2 parents 1e73cd9 + da8155a commit 911e309
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 78 deletions.
148 changes: 88 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/plugin-proposal-pipeline-operator": "^7.3.2",
"@babel/preset-env": "^7.3.4",
"@fink/larix": "^4.0.0",
"@babel/preset-env": "^7.8.6",
"@fink/larix": "^4.1.0",
"@nearmap/eslint-config-base": "^1.1.0",
"babel-eslint": "^10.1.0",
"commitizen": "^4.0.3",
Expand All @@ -51,8 +51,8 @@
"semantic-release": "^17.0.4"
},
"dependencies": {
"@babel/generator": "^7.8.4",
"@babel/traverse": "^7.8.4",
"@babel/types": "^7.8.3"
"@babel/generator": "^7.8.6",
"@babel/traverse": "^7.8.6",
"@babel/types": "^7.8.6"
}
}
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ const binary_ops = {

'.': transform_member,

call: transform_call
call: transform_call,
infix: transform_inifx
};

const block_like = {
Expand Down Expand Up @@ -119,8 +120,7 @@ const transformers = {
...block_like,
...control_flow,
...iterables,
...jsx,
infix: transform_inifx
...jsx
};


Expand Down
12 changes: 12 additions & 0 deletions src/transform/__snapshots__/object.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`calculated props 1`] = `
"const foo = {
\\"foo\\": foo,
[Symbol(\`foo\`)]: 123,
[\`spam\`]: 456,
\\"ni\\": ni
};
Object.assign(module.exports, {
foo
});"
`;
exports[`destructuring object 1`] = `
"const {
\\"a\\": a,
Expand Down
21 changes: 11 additions & 10 deletions src/transform/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@ const str_key = ({value, loc})=> (
);


const get_key = ({key}, ctx)=> {
if (key.type === 'group' || key.type === 'string') {
return [ctx.transform(key), true];
}

return [str_key(key), false];
};


export const transform_prop = (node, ctx)=> {
if (node.key.type === 'spread') {
return ctx.transform(node.key);
}

const is_str_key = node.key.type === 'string';
const is_default_assignment = node.value.type === 'assign';

const key = (
is_str_key
? ctx.transform(node.key)
: str_key(node.key)
);

const [key, computed] = get_key(node, ctx);
const value = ctx.transform(node.value);

const computed = is_str_key;
const shorthand = (node.key === node.value);
const is_default_assignment = node.value.type === 'assign';

return objectProperty(
key,
Expand Down
Loading

0 comments on commit 911e309

Please sign in to comment.