pugjs / constantinople Goto Github PK
View Code? Open in Web Editor NEWDetermine whether a JavaScript expression evaluates to a constant (using Acorn)
License: MIT License
Determine whether a JavaScript expression evaluates to a constant (using Acorn)
License: MIT License
Hello,
I need a way to work with undefined when parsing.
For example the expression
(foo.bar === underfined) ? 1: 2 not working.
Also
typeof foo['bar'] === ''undefined' - not constant
foo['bar'] === 'undefined - not constant
foo['bar'] == undefined - not constant
this is document
my test file a.js
const md = require("jstransformer")(require("jstransformer-markdown-it"));
const { resolve } = require("path");
const FS = require("fs");
console.log(md.render("# hello"));
console.log(md.renderFile("./a.md"));
const pug = require("pug");
const source = `
p some ss #[:md(inline='true') # hello]
include:md /a.md
`;
var html = pug.compile(source, {
basedir: __dirname,
filters: {
md: (text, opts) => {
console.log(opts);
if (opts.inline) {
return md.render(text).body;
}
if (opts.filename) {
return md.renderFile(opts.filename).body;
}
}
}
});
console.log(html());
it's work , i use string ‘true’ bypass constantinople
logic 。 when i use #[:md(inline) # hello]
i got an error true is not constant. All filters are rendered compile-time so filter options must be constants
when i use include:md ./a.md
or include:md a.md
i read the error source code , find the path need start with '/' so ,i add '/' bypass the logic。
did have something config let my code keep with document? 3q~ 🙏
...entirely because of the babylon
/babel-type
dependencies. this adds a not-inconsiderable amount of needless runtime bloat that's quite painful to e.g. FTP deploy node_modules
, even with mechanisms like .yarnclean
to soften the blow.
you can see just how much the package bloated since the switch on packagephobia. it's quite the jump.
the original PR mentioned it was so people could "get the latest JS features", but that was almost 3 years ago & things have changed substantially since then.
as other parts of the pug tree already rely on acorn
-- which is zero dependency & doesn't suffer from these issues as a result -- i would seriously recommend at the very least evaluating if returning to acorn
is viable.
i would be willing to contribute work here.
Hi
We have started getting the following error in our application for last few days(approx 5 days)..
SyntaxError: Unexpected token (580:263)
at Parser.pp$4.raise (../../node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:2488:13)
at Parser.pp.unexpected ../../node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:623:8)
at Parser.pp.expect (../../node_modules/acorn/dist/acorn.js:617:26)
at Parser.pp$3.parseExprList (../../node_modules/acorn/dist/acorn.js:2406:14)
at Parser.pp$3.parseSubscripts ../../node_modules/acorn/dist/acorn.js:1900:29)
at Parser.pp$3.parseExprSubscripts (../../node_modules/acorn/dist/acorn.js:1875:21)
at Parser.pp$3.parseMaybeUnary ../../node_modules/acorn/dist/acorn.js:1849:17)
at Parser.pp$3.parseExprOp ../../node_modules/acorn/dist/acorn.js:1810:41)
at Parser.pp$3.parseExprOp (../../node_modules/acorn/dist/acorn.js:1812:19)
at Parser.pp$3.parseExprOp (../../node_modules/acorn/dist/acorn.js:1812:19)
at Parser.pp$3.parseExprOps (../../node_modules/acorn/dist/acorn.js:1793:15)
at Parser.pp$3.parseMaybeConditional (../../node_modules/acorn/dist/acorn.js:1774:19)
at Parser.pp$3.parseMaybeAssign (../../node_modules/acorn/dist/acorn.js:1750:19)
at Parser.pp$3.parseParenAndDistinguishExpression (../../node_modules/acorn/dist/acorn.js:2056:30)
at Parser.pp$3.parseExprAtom (../../node_modules/acorn/dist/acorn.js:1978:41)
at Parser.pp$3.parseExprSubscripts (../../node_modules/acorn/dist/acorn.js:1872:19)
at Parser.pp$3.parseMaybeUnary (../../node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:1849:17)
at Parser.pp$3.parseExprOp (/../../node_modules/acorn/dist/acorn.js:1810:41)
at Parser.pp$3.parseExprOp (../../node_modules/acorn/dist/acorn.js:1812:19)
at Parser.pp$3.parseExprOps (../../node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:1793:15)
at Parser.pp$3.parseMaybeConditional (../../node_modules/acorn/dist/acorn.js:1774:19)
at Parser.pp$3.parseMaybeAssign (../../node_modules/acorn/dist/acorn.js:1750:19)
at Parser.pp$3.parseMaybeAssign (../../node_modules/acorn/dist/acorn.js:1761:23)
at Parser.pp$3.parseExpression (../../node_modules/acorn/dist/acorn.js:1722:19)
at Parser.pp$1.parseStatement (../../node_modules/acorn/dist/acorn.js:777:45)
at Parser.pp$1.parseBlock (../../node_modules/acorn/dist/acorn.js:1040:23)
at Parser.pp$1.parseStatement (../../node_modules/acorn/dist/acorn.js:754:31)
at Parser.pp$1.parseIfStatement (../../node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:879:26)
Getting this error with 3.1.2 version of constantinople. However if I replace with with an earlier version of the module, the error goes away.
Could you please suggest what could be the issue ..?
Thanks ..
In https://www.npmjs.com/package/babel-types I see that the linked repository apears not the correct one.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.