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

Test: if the input file already has a get-originals import #32

Open
domenic opened this issue Aug 9, 2019 · 1 comment
Open

Test: if the input file already has a get-originals import #32

domenic opened this issue Aug 9, 2019 · 1 comment
Milestone

Comments

@domenic
Copy link
Collaborator

domenic commented Aug 9, 2019

Consider a case where someone wants to use get-originals directly, because it's more convenient. This is the case certain parts of Chromium's KV Storage implementation. In this case the input file might look like

import { apply } from "std:global/Reflect";
import { byteLength_get } from "std:global/ArrayBuffer";

const a = new ArrayBuffer();
a.byteLength;

function isArrayBuffer(value) {
  try {
    apply(byteLength_get, value);
    return true;
  } catch {
    return false;
  }
}

The result here should be one of:

Use existing import names

import { apply } from "std:global/Reflect";
import ArrayBuffer, { byteLength_get } from "std:global/ArrayBuffer";

const a = new ArrayBuffer();
apply(byteLength_get, a);

function isArrayBuffer(value) {
  try {
    apply(byteLength_get, value);
    return true;
  } catch {
    return false;
  }
}

or

Introduce the usual import names alongside existing ones

import { apply, apply as Reflect_apply } from "std:global/Reflect";
import ArrayBuffer, { byteLength_get, byteLength_get as ArrayBuffer_byteLength_get } from "std:global/ArrayBuffer";

const a = new ArrayBuffer();
Reflect_apply(ArrayBuffer_byteLength_get, a);

function isArrayBuffer(value) {
  try {
    apply(byteLength_get, value);
    return true;
  } catch {
    return false;
  }
}

or

Give an error

Something useful, like "Saw apply imported from "std:global/Reflect"; expected it to be imported as reflect_apply", which would encourage people to feed input files with the expected naming pattern in the first place.

@domenic domenic added this to the Solid core milestone Aug 9, 2019
@domenic
Copy link
Collaborator Author

domenic commented Aug 9, 2019

It occurs to me "Give an error" might be pretty easy to implement as an initial pass.

That still leaves writing tests that an input using names such as

import { apply as Reflect_apply } from "std:global/Reflect";
import { byteLength_get ArrayBuffer_byteLength_get } from "std:global/ArrayBuffer";

const a = new ArrayBuffer();
a.byteLength;

function isArrayBuffer(value) {
  try {
    Reflect_apply(byteLength_get, value);
    return true;
  } catch {
    return false;
  }
}

gets transformed into

import { apply as Reflect_apply } from "std:global/Reflect";
import ArrayBuffer, { byteLength_get as ArrayBuffer_byteLength_get } from "std:global/ArrayBuffer";

const a = new ArrayBuffer();
Reflect_apply(ArrayBuffer_byteLength_get, a);

function isArrayBuffer(value) {
  try {
    Reflect_apply(ArrayBuffer_byteLength_get, value);
    return true;
  } catch {
    return false;
  }
}

@domenic domenic modified the milestones: Solid core, Polish Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant