Skip to content

Commit

Permalink
fix: fix import of generated parser/lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbllmnn committed Jun 20, 2024
1 parent ab06203 commit 083cfba
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"main": "dist/CqlParser.js",
"module": "dist/CqlParser.js",
"types": "dist/CqlParser.d.ts",
"browser": "dist/geostyler-cql-parser.iife.js",
"files": [
"dist",
"index.d.ts"
Expand All @@ -28,9 +27,8 @@
},
"homepage": "https://github.com/geostyler/geostyler-cql-parser#readme",
"scripts": {
"generate": "jison -m commonjs ./src/cql.jison -o ./src/cql-parser.cjs",
"build:browser": "vite build",
"build": "npm run build:browser && tsc && cp ./src/cql-parser.js ./dist",
"generate": "jison -m js ./src/cql.jison -o ./src/cql-parser.cjs && sed -i 's;var cqlParser;window.cqlParser;g' ./src/cql-parser.cjs",
"build": "tsc && cp ./src/cql-parser.cjs ./dist",
"lint": "eslint -c .eslintrc.cjs --ext ts,spec.ts src/",
"typecheck": "tsc --noEmit --project tsconfig.json",
"prebuild": "npm run test",
Expand Down
7 changes: 4 additions & 3 deletions src/CqlParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
isNaN as _isNaN
} from 'lodash';

// @ts-ignore:next-line
import * as Parser from './cql-parser';
import './cql-parser.cjs';

import { CombinationOperator, Expression, Filter, Operator, PropertyType } from 'geostyler-style/dist/style';

type PatternName = 'PROPERTY' | 'COMPARISON' | 'VALUE' | 'LOGICAL' | 'LPAREN' | 'RPAREN'
Expand Down Expand Up @@ -92,7 +92,8 @@ export class CqlParser {

read(text: string | undefined): Filter | Expression<PropertyType> | undefined {
try {
return Parser.parse(text);
// @ts-expect-error
return cqlParser.parse(text);
} catch (e) {
return undefined;
}
Expand Down
11 changes: 2 additions & 9 deletions src/cql-parser.js → src/cql-parser.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
}
*/
var cqlParser = (function(){
window.cqlParser = (function(){
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,29],$V1=[1,30],$V2=[1,31],$V3=[1,32],$V4=[1,33],$V5=[1,34],$V6=[1,21],$V7=[1,22],$V8=[1,13],$V9=[1,28],$Va=[1,23],$Vb=[1,24],$Vc=[1,25],$Vd=[1,26],$Ve=[1,27],$Vf=[1,14],$Vg=[1,15],$Vh=[1,5],$Vi=[1,39],$Vj=[1,36],$Vk=[1,37],$Vl=[1,38],$Vm=[5,24,25,33,34,36,39,50,70,86,87,88],$Vn=[5,24,25,33,34,36,39,50,70,75,76,77,78,79,80,81,83,86,87,88],$Vo=[1,56],$Vp=[1,57],$Vq=[1,52],$Vr=[1,53],$Vs=[1,54],$Vt=[1,55],$Vu=[1,58],$Vv=[1,59],$Vw=[1,60],$Vx=[1,61],$Vy=[1,62],$Vz=[1,63],$VA=[1,64],$VB=[2,57],$VC=[5,24,25,33,34,36,39,41,43,50,52,53,54,55,56,57,58,59,60,61,63,67,69,70,71,72,73,75,76,77,78,79,80,81,83,86,87,88],$VD=[5,24,25,33,34,36,39,41,43,50,52,53,54,55,56,57,58,59,60,61,63,65,67,69,70,71,72,73,75,76,77,78,79,80,81,83,86,87,88],$VE=[1,65],$VF=[2,20],$VG=[9,11,12,14,15,17,19,21,22,38,41,43,44,45,46,48,49],$VH=[1,104],$VI=[24,25],$VJ=[2,18],$VK=[5,24,25,33,34,36,39,50,87,88],$VL=[5,24,25,33,34,36,39,50,52,53,54,55,61,63,67,69,70,71,72,73,75,76,77,78,79,80,81,83,86,87,88],$VM=[5,24,25,33,34,36,39,41,43,50,52,53,54,55,61,63,67,69,70,71,72,73,75,76,77,78,79,80,81,83,86,87,88],$VN=[33,36,39];
var parser = {trace: function trace () { },
yy: {},
Expand Down Expand Up @@ -1013,11 +1013,4 @@ function Parser () {
}
Parser.prototype = parser;parser.Parser = Parser;
return new Parser;
})();


if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
exports.parser = cqlParser;
exports.Parser = cqlParser.Parser;
exports.parse = function () { return cqlParser.parse.apply(cqlParser, arguments); };
}
})();
26 changes: 13 additions & 13 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import react from '@vitejs/plugin-react';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
build: {
manifest: true,
lib: {
entry: './src/CqlParser.ts',
name: 'GeoStyler',
formats: ['iife'],
fileName: 'geostyler-cql-parser',
},
sourcemap: true,
},
define: {
appName: 'GeoStylerCqlParser'
},
// build: {
// manifest: true,
// lib: {
// entry: './src/CqlParser.ts',
// name: 'GeoStylerCqlParser',
// formats: ['iife'],
// fileName: 'geostyler-cql-parser',
// },
// sourcemap: true,
// },
// define: {
// appName: 'GeoStylerCqlParser'
// },
server: {
host: '0.0.0.0'
}
Expand Down

0 comments on commit 083cfba

Please sign in to comment.