Socket
Socket
Sign inDemoInstall

babel-plugin-ts-optchain

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.0.3

37

__tests__/plugin.test.ts

@@ -130,1 +130,38 @@ import dedent from "dedent";

});
test("can handle function in accessor in the leaf getter", async () => {
const code = dedent`
import { oc } from "ts-optchain";
oc(data).foo.bar.baz[last(1)]();
`;
const res = runPlugin(code);
expect(res.code).toEqual(dedent`
import { oc } from "babel-plugin-ts-optchain/lib/runtime";
oc(data, ["foo", "bar", "baz", last(1)]);
`);
});
test("has good error message when chain does not end with function call", async () => {
const code = dedent`
import { oc } from "ts-optchain";
const foo = oc(data).foo;
const bar = foo.bar();
`;
expect(() => {
runPlugin(code);
}).toThrow("Last property accessor in ts-optchain must be a function call");
});
test("has good error message when there are no property accessors at all", async () => {
const code = dedent`
import { oc } from "ts-optchain";
const x = oc(data);
const bar = x.bar();
`;
expect(() => {
runPlugin(code);
}).toThrow("You must add at least one property accessor to oc() calls");
});

2

package.json
{
"name": "babel-plugin-ts-optchain",
"version": "1.0.2",
"version": "1.0.3",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/plugin.js",

@@ -35,3 +35,18 @@ # babel-plugin-ts-optchain

## Limitations
You must call `oc()` in a single chain. Eg. this does not work:
```ts
const x = oc(data);
const bar = x.foo.bar();
```
Write it like this
```ts
const bar = oc(data).foo.bar();
```
[ts-optchain]: https://github.com/rimeto/ts-optchain
[mb]: https://github.com/burakcan/mb

@@ -31,2 +31,13 @@ import * as types from "@babel/types";

defaultValue = path.parent.arguments[0];
} else {
if (t.isMemberExpression(path.node)) {
throw new Error(
"Last property accessor in ts-optchain must be a function call. " +
`Add () to .${path.node.property.name};`,
);
} else {
throw new Error(
"You must add at least one property accessor to oc() calls",
);
}
}

@@ -33,0 +44,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc