Comments (19)
I'm not able to reproduce that on my end. Can you share the full example? What values do the variables exporters
and importsForV
contain?
from deno.
I'm not able to reproduce that on my end. Can you share the full example? What values do the variables
exporters
andimportsForV
contain?
They have same element,
exporters = ["no", "tests"]
importsForV = ["no", "tests"]
The whole code is actually preety long and the values are not hardcoded into those arrays, but i log out the values of both of them and it was the same, that's why .every works, i also tried it on node and bun, it also works
Entire file incase needed:
#!/usr/bin/env -S deno run -A
import { objectChecker } from "./error_handling/objectChCompiled.js";
const out = "./out.js"; // Using Deno.cwd() to get current working directory Deno.cwd().slice(2) +
const programName = Deno.args[0]; // Using Deno.args to get command line arguments
// const buf = new Uint8Array(2000)
// await Deno.openSync(programName).read(buf)
const program = Deno.readTextFileSync(programName);
// this function breaks the whole program into lines
function parse(codes: string): string[] {
return codes.split("\n");
}
// this function breaks a line into words by white space
// function tokenize(code: string): string[] {
// return code.split(/\s+/);
// }
// this function is peak
function parser(inputString: string) {
// Separate the input string into segments
const segments = inputString.match(/(["'`].*?["'`])|\S+/g);
if (!segments) return [];
const result: string[] | any = [];
for (const segment of segments) {
if (
segment.startsWith('"') || segment.startsWith("'") ||
segment.startsWith("`")
) {
// Quoted strings
result.push(segment);
} else {
// Split by parentheses, square brackets, braces, and operators
const tokens = segment.split(/([()\[\]{}])/).filter((token) =>
token.trim() !== ""
);
// Combine adjacent parentheses, square brackets, or braces
let combinedToken = "";
for (const token of tokens) {
if (
token === "(" || token === "[" || token === "{" || token === ")" ||
token === "]" || token === "}"
) {
if (combinedToken !== "") {
result.push(combinedToken);
combinedToken = "";
}
result.push(token);
} else {
combinedToken += token;
}
}
// Push any remaining combined token
if (combinedToken !== "") {
result.push(combinedToken);
}
}
}
return result;
}
function parseStr(inputString: string) {
const regex = /(["'`])(.*?)\1|\S+/g;
const matches = inputString.match(regex);
if (matches) {
return matches;
} else {
return [];
}
}
// this function breaks a quote statement apart
// function parseStatement(statement): string[] {
// const regex = /"([^"]+)"|(\w+)|([=\[\]\(\){}รท*+\-])/g; // Matches either a quoted string or a word /("[^"]+"|\w+)/g
// const matches = statement.match(regex);
// return matches;
// }
let exporters: string[] = [];
function generateCode(program: any) {
let code = "";
let lines = parse(program);
let newLines = lines.filter((line) => {
return line.trim() !== "";
});
if (newLines[0] == "\\r") {
newLines[0] = "\n";
}
if (newLines[0].includes("#")) {
newLines[0] = "";
}
newLines.forEach((el) => {
el.includes("{")
? (el += "")
: el.includes(";")
? (el += "")
: el.includes("}")
? (el += "")
: el.includes(",")
? (el += "")
: el.includes(":")
? (el += "")
: el.includes("imp@") ? el += '' : (el += " ;");
let values: RegExpMatchArray | never[] | string[] = parseStr(el);
if (
el.includes("for (") || el.includes("for(") || el.includes("if(") ||
el.includes("if (") || el.includes("exp@ f")
) {
values = parser(el);
}
values[values.length] = "\n";
for (let i = 0; i < values.length; i++) {
if (values[i] == "l") {
values[i] = "let";
}
if (values[i] == "print") {
values[i] = `console.log(${values[i + 1]})`;
values[i + 1] = " ";
}
if (values[i] == "f") {
values[i] = "function";
}
if (values[i] == "exp@") {
exporters.push(values[i + 2]); // exported variable name to list of exported in a file
values[i] = "export";
}
if (values[i] == "imp@") {
// let impe = imp(values, values[i]);
// values[i] = impe
const impStatementLength = values.length;
// import for variable
let importForV = values[i + 1].slice(1, -1);
const endMark = impStatementLength - 2;
// import location
let importLocation = values[endMark];
const impLength = importLocation.length;
importLocation = importLocation.slice(1, impLength - 1);
const ayImport = Deno.readTextFileSync(
`${Deno.cwd()}${importLocation}`,
);
// console.log(values[i],values[impStatementLength - 3])
// console.log(importForV,importLocation,values)
values[i] = "";
values[i + 1] = "";
values[2] = "";
values[endMark] = "";
if (importForV == importLocation) {
code += generateCode(ayImport);
} else {
//to do actually make sure the file isn't loaded and executed
let importsForV: string[] = [];
let condition: any;
if (importForV.split(",").length > 1) {
importsForV = importForV.split(",");
//for some reason every works in deno and some doesn't
condition = exporters.every((r) => importsForV.includes(r));
for (let i = 0; i < importsForV.length; i++) {
if (condition) {
importForV = importsForV.join(", ");
}
}
}
const tempCode = generateCode(ayImport);
if (exporters.includes(importForV) || condition) {
const math =
`import {rand, round, PI, floor, exp, degToRad, radToDeg} from './math.ts';\n`;
const utils =
`import {print, timer, Day, interval, read, write, appendFile, dirname} from './utils.js';\n`;
const AY = `import {AY} from './objects/AY.js';\n`;
const exec = ` ${math} ${utils} ${AY} ${tempCode} `;
const out2 = import.meta.dirname + "/out2.js";
Deno.writeTextFileSync(out2, exec);
code += `import {${importForV}} from "./out2.js"`;
}
if (!exporters.includes(importForV) && !condition) {
console.log("exports: ", exporters);
console.log("No exports found", importForV);
Deno.exit(1);
}
}
}
}
// switch case will only be used for error handling
// switch (values[0]) {
// case 'l':
// values[0] = 'let';
// break;
// case 'print':
// values[0] = `console.log(${values[1]});`;
// values[1] = ' '
// break;
// case 'f':
// values[0] = `function`;
// break;
// default:
// break ;
// }
// values = values.filter(value => value !== undefined || value !== null)
code += values.join(" ");
});
return code;
}
const math =
`import {rand, round, PI, floor, exp, degToRad, radToDeg} from './math.ts';\n`;
const utils =
`import {print, timer, Day, interval, read, write, appendFile, dirname} from './utils.js';\n`;
const AY = `import {AY} from './objects/AY.js';\n`;
const some = generateCode(program);
const exec = `${math}${utils}${AY} ${some} `;
objectChecker(some);
Deno.writeTextFileSync(out, exec);
import(out);
from deno.
I'm not able to reproduce it:
const exporters = ["no", "tests"];
const importsForV = ["no", "tests"];
// Logs: true
console.log(exporters.some((r) => importsForV.includes(r)));
// Logs: true
console.log(exporters.every((r) => importsForV.includes(r)));
from deno.
I'm not able to reproduce it:
const exporters = ["no", "tests"]; const importsForV = ["no", "tests"]; // Logs: true console.log(exporters.some((r) => importsForV.includes(r))); // Logs: true console.log(exporters.every((r) => importsForV.includes(r)));
what version of deno are you using, i'll upgrade to that?
Thank you so much by the way
from deno.
Ran a script that tried every version from 1.30.0
to 1.43.6
. All of them work. Given that those Array methods are defined inside v8
itself, it seems unlikely that the bug is there. Otherwise the same issue would be present in Node or Chrome. Maybe something else is going on in the code and it fails elsewhere?
from deno.
Ran a script that tried every version from
1.30.0
to1.43.6
. All of them work. Given that those Array methods are defined insidev8
itself, it seems unlikely that the bug is there. Otherwise the same issue would be present in Node or Chrome. Maybe something else is going on in the code and it fails elsewhere?
Yes i was also shocked maybe i'll reinstall deno, also when i check my task manager deno seems to be using up memory, when i'm not running it, what could be the cause
from deno.
Ran a script that tried every version from
1.30.0
to1.43.6
. All of them work. Given that those Array methods are defined insidev8
itself, it seems unlikely that the bug is there. Otherwise the same issue would be present in Node or Chrome. Maybe something else is going on in the code and it fails elsewhere?
So i did some login again and this is exactly what i have as the array values of the 2 elements:
importsForV: [ " no", " tests" ]
exports: [ "no", "tests"
]```
it still doesn't work and i just upgraded my version
from deno.
@MikeyA-yo do you have a repository that shows the reproduction? That code imports ./error_handling/objectChCompiled.js
so we might not be able to reproduce it.
from deno.
@MikeyA-yo do you have a repository that shows the reproduction? That code imports
./error_handling/objectChCompiled.js
so we might not be able to reproduce it.
This is the full link to the exact code: https://github.com/MikeyA-yo/ay-ts-deno
To test run ./ay.ts then pass in test.ay as a CLI argument (I'm build a JIT transpiler with deno)
from deno.
@MikeyA-yo it's because the array is empty. .every
returns true for empty arrays, but some
will return false.
from deno.
@MikeyA-yo it's because the array is empty.
.every
returns true for empty arrays, butsome
will return false.
No, not on my end, when i log the array, i see values i need, also it works on bun and node, exactly similar code, so that can't be it, but i'll leave it as that since you already added invalid tag.
Important Note The Array Is Not Empty
from deno.
Ran a script that tried every version from
1.30.0
to1.43.6
. All of them work. Given that those Array methods are defined insidev8
itself, it seems unlikely that the bug is there. Otherwise the same issue would be present in Node or Chrome. Maybe something else is going on in the code and it fails elsewhere?So i did some login again and this is exactly what i have as the array values of the 2 elements:
importsForV: [ " no", " tests" ] exports: [ "no", "tests" ]``` it still doesn't work and i just upgraded my version
@dsherret I did some console.log and that is exactly what i see, so the array isn't empty
from deno.
@dsherret i'll leave this closed but i'd appreciate if you can try to look more into it
from deno.
Do the strings contain whitespace? Strings with different amounts or different kinds of whitespace compare unequal. Only strings with exactly the same characters at the same positions are equal. For example, " no" === "no"
returns false
because the left-hand string starts with a space character while the right-hand string does not.
from deno.
@MikeyA-yo when I run:
./ay.ts test.ay
...in that repo, I get an empty array for exporters
.
from deno.
Do the strings contain whitespace? Strings with different amounts or different kinds of whitespace compare unequal. Only strings with exactly the same characters at the same positions are equal. For example,
" no" === "no"
returnsfalse
because the left-hand string starts with a space character while the right-hand string does not.
Yes it did
from deno.
Where are you logging it, how can we have different results, now i don't understand the reason for this
from deno.
from deno.
wow, ohk
from deno.
Related Issues (20)
- Bug in deno publish --dry-run with super expression and spread syntax
- `setTimeout` is not running as expected when using `prompt()` HOT 7
- Extremely high memory usage
- OOME new in Deno 1.44 HOT 1
- v1.44.0 gRPC client support doesn't work
- ext/node: net.BlockList needs to be implemented for dd-trace
- node:diagnostic_channel misses `DiagnosticChannel::tracingChannel` API
- Cannot read properties of undefined (reading 'env') HOT 1
- Allow classes with `fetch` method for `deno serve`.
- thread 'worker-2' panicked at cli/npm/managed/resolution.rs:231:72: called `Option::unwrap()` on a `None` value HOT 6
- Uncaught SyntaxError: Unexpected reserved word HOT 2
- dynamic import of async module from worker HOT 2
- Make test output slightly easier to read HOT 1
- bug: `JSR package manifest for '@std/uuid' failed to load. Access is denied. (os error 5)` in `std` HOT 2
- `websocket.send()` does not respect the order of messages HOT 1
- `deno publish` to jsr does not resolve `@deno-types="..."`
- `Napi::Buffer<uint8_t>` produces a Uint8Array instead of a NodeJs `Buffer` HOT 1
- Access-Control-Allow-Methods not reflected on the response header when integrated with Hono HOT 1
- internal error: entered unreachable code: Expected at least one stalled top-level await HOT 10
- Types don't load if alias in import map isn't exact match of package name when importing `currency.js` from npm HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deno.