Skip to content

Commit

Permalink
Merge remote-tracking branch 'mjgp2/bigint'
Browse files Browse the repository at this point in the history
  • Loading branch information
mehcode committed Aug 23, 2022
2 parents 1b28894 + e24adf2 commit 7aa864d
Show file tree
Hide file tree
Showing 35 changed files with 623 additions and 901 deletions.
58 changes: 29 additions & 29 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,47 @@ name: "Test"
on:
push:
branches:
- master
- master
pull_request:
types: [assigned, opened, synchronize, reopened, labeled]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: "12"
- name: "Install dependencies"
run: npm install
- name: "Lint sources"
run: npm run lint:sources -- --max-warnings 0
- name: "Lint types"
run: npm run lint:types
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: "12"
- name: "Install dependencies"
run: npm install
- name: "Lint sources"
run: npm run lint:sources -- --max-warnings 0
- name: "Lint types"
run: npm run lint:types
test:
runs-on: ubuntu-latest
strategy:
matrix:
node_version: ["12", "14", "16", "18"]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node_version }}
- name: "Install dependencies"
run: npm install
- name: "Test sources"
run: npm run test:sources
- name: "Test types"
run: npm run test:types
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node_version }}
- name: "Install dependencies"
run: npm install
- name: "Test sources"
run: npm run test:sources
- name: "Test types"
run: npm run test:types
bench:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: "12"
- name: "Install dependencies"
run: npm install
- name: "Run benchmark"
run: npm run bench
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: "12"
- name: "Install dependencies"
run: npm install
- name: "Run benchmark"
run: npm run bench
6 changes: 1 addition & 5 deletions bench/data/bench.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
"inner" : {
"int32" : 20161110,
"innerInner" : {
"long" : {
"low": 1051,
"high": 151234,
"unsigned": false
},
"long" : "34857897489505",
"enum" : 1,
"sint32": -42
},
Expand Down
2 changes: 1 addition & 1 deletion bench/data/static_pbjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ $root.Test = (function() {
this[keys[i]] = properties[keys[i]];
}

InnerInner.prototype.long = $util.Long ? $util.Long.fromBits(0,0,false) : 0;
InnerInner.prototype.long = 0n;
InnerInner.prototype["enum"] = 0;
InnerInner.prototype.sint32 = 0;

Expand Down
2 changes: 1 addition & 1 deletion cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function beautifyCode(code) {
output: { beautify: true }
}).code;
// Properly beautify
var ast = espree.parse(code);
var ast = espree.parse(code, { ecmaVersion: 2020 });
estraverse.replace(ast, {
enter: function(node, parent) {
// rename short vars
Expand Down Expand Up @@ -227,7 +227,7 @@ function buildFunction(type, functionName, gen, scope) {
var code = gen.toString(functionName)
.replace(/((?!\.)types\[\d+])(\.values)/g, "$1"); // enums: use types[N] instead of reflected types[N].values

var ast = espree.parse(code);
var ast = espree.parse(code, { ecmaVersion: 2020 });
/* eslint-disable no-extra-parens */
estraverse.replace(ast, {
enter: function(node, parent) {
Expand Down Expand Up @@ -329,7 +329,7 @@ function toJsType(field) {
case "sint64":
case "fixed64":
case "sfixed64":
type = config.forceLong ? "Long" : config.forceNumber ? "number" : "number|Long";
type = "bigint";
break;
case "bool":
type = "boolean";
Expand Down Expand Up @@ -413,11 +413,7 @@ function buildType(ref, type) {
else if (field.partOf || field.optional && config["null-defaults"])
push(escapeName(type.name) + ".prototype" + prop + " = null;"); // do not set default value for oneof members
else if (field.long)
push(escapeName(type.name) + ".prototype" + prop + " = $util.Long ? $util.Long.fromBits("
+ JSON.stringify(field.typeDefault.low) + ","
+ JSON.stringify(field.typeDefault.high) + ","
+ JSON.stringify(field.typeDefault.unsigned)
+ ") : " + field.typeDefault.toNumber(field.type.charAt(0) === "u") + ";");
push(escapeName(type.name) + ".prototype" + prop + " = " + field.typeDefault + "n;");
else if (field.bytes) {
push(escapeName(type.name) + ".prototype" + prop + " = $util.newBuffer(" + JSON.stringify(Array.prototype.slice.call(field.typeDefault)) + ");");
} else
Expand Down
238 changes: 119 additions & 119 deletions config/eslint.json
Original file line number Diff line number Diff line change
@@ -1,127 +1,127 @@
{
"env": {
"node": true,
"browser": true
},
"globals": {
"ArrayBuffer": true,
"Uint8Array": true,
"Float32Array": true,
"Float64Array": true,
"define": true,
"global": true,
"XMLHttpRequest": true,
"Promise": true
},
"parserOptions": {
"ecmaVersion": 6
},
"extends": "eslint:recommended",
"rules": {
"env": {
"node": true,
"browser": true,
"es2020": true
},
"globals": {
"ArrayBuffer": true,
"Uint8Array": true,
"Float32Array": true,
"Float64Array": true,
"define": true,
"global": true,
"XMLHttpRequest": true,
"Promise": true
},
"parserOptions": {
"ecmaVersion": 2020
},
"extends": "eslint:recommended",
"rules": {
// Possible errors
"no-extra-parens": 1, // turned on as the daily lecture
"no-prototype-builtins": 1,
"no-template-curly-in-string": 1,
"no-unsafe-negation": 1,
"valid-jsdoc": 1,

// Possible errors
"no-extra-parens": 1, // turned on as the daily lecture
"no-prototype-builtins": 1,
"no-template-curly-in-string": 1,
"no-unsafe-negation": 1,
"valid-jsdoc": 1,
// Best practices
"accessor-pairs": 1,
"array-callback-return": 1,
"block-scoped-var": 1,
"class-methods-use-this": 1,
"complexity": 0, // is sometimes necessary
"consistent-return": 1,
"curly": 0, // sometimes more braces than code
"default-case": 0, // just forces unnecessary code
"dot-location": 0, // looks nicer for chainables
"dot-notation": 0, // not compatible with some reserved properties
"eqeqeq": [1, "allow-null"],
"guard-for-in": 1,
"no-alert": 1,
"no-caller": 1,
"no-cond-assign": 0,
"no-div-regex": 1,
"no-else-return": 1,
"no-empty-function": 1,
"no-eval": 1,
"no-extend-native": 1,
"no-extra-bind": 1,
"no-extra-label": 1,
"no-floating-decimal": 1,
"no-global-assign": 1,
"no-implicit-coercion": 1,
"no-implicit-globals": 1,
"no-implied-eval": 1,
"no-invalid-this": 1,
"no-iterator": 1,
"no-labels": 1,
"no-lone-blocks": 1,
"no-loop-func": 1,
"no-magic-numbers": 0, // it's actually fun to turn this on here
"no-new-func": 1,
"no-new-wrappers": 1,
"no-new": 1,
"no-octal-escape": 1,
"no-param-reassign": 0, // is necessary for varargs functions
"no-proto": 1,
"no-restricted-properties": 1,
"no-sequences": 1,
"no-script-url": 1,
"no-self-compare": 1,
"no-throw-literal": 1,
"no-unmodified-loop-condition": 1,
"no-unused-expressions": ["error", { "allowShortCircuit": true }],
"no-useless-call": 1,
"no-useless-concat": 1,
"no-useless-escape": 1,
"no-useless-return": 1,
"no-void": 1,
"no-warning-comments": 1,
"no-with": 1,
"radix": 1,
"vars-on-top": 0, // makes code harder to read, not faster
"wrap-iife": 0, // used frequently where polyfilling
"yoda": 1,

// Best practices
"accessor-pairs": 1,
"array-callback-return": 1,
"block-scoped-var": 1,
"class-methods-use-this": 1,
"complexity": 0, // is sometimes necessary
"consistent-return": 1,
"curly": 0, // sometimes more braces than code
"default-case": 0, // just forces unnecessary code
"dot-location": 0, // looks nicer for chainables
"dot-notation": 0, // not compatible with some reserved properties
"eqeqeq": [1, "allow-null"],
"guard-for-in": 1,
"no-alert": 1,
"no-caller": 1,
"no-cond-assign": 0,
"no-div-regex": 1,
"no-else-return": 1,
"no-empty-function": 1,
"no-eval": 1,
"no-extend-native": 1,
"no-extra-bind": 1,
"no-extra-label": 1,
"no-floating-decimal": 1,
"no-global-assign": 1,
"no-implicit-coercion": 1,
"no-implicit-globals": 1,
"no-implied-eval": 1,
"no-invalid-this": 1,
"no-iterator": 1,
"no-labels": 1,
"no-lone-blocks": 1,
"no-loop-func": 1,
"no-magic-numbers": 0, // it's actually fun to turn this on here
"no-new-func": 1,
"no-new-wrappers": 1,
"no-new": 1,
"no-octal-escape": 1,
"no-param-reassign": 0, // is necessary for varargs functions
"no-proto": 1,
"no-restricted-properties": 1,
"no-sequences": 1,
"no-script-url": 1,
"no-self-compare": 1,
"no-throw-literal": 1,
"no-unmodified-loop-condition": 1,
"no-unused-expressions": ["error", { "allowShortCircuit": true }],
"no-useless-call": 1,
"no-useless-concat": 1,
"no-useless-escape": 1,
"no-useless-return": 1,
"no-void": 1,
"no-warning-comments": 1,
"no-with": 1,
"radix": 1,
"vars-on-top": 0, // makes code harder to read, not faster
"wrap-iife": 0, // used frequently where polyfilling
"yoda": 1,
// Strict mode
"strict": 1,

// Strict mode
"strict": 1,
// Variables
"init-declarations": 0, // because no-undef-init is on and we actually want undefineds
"no-catch-shadow": 0, // no IE8 support anyway
"no-label-var": 1,
"no-restricted-globals": 1,
"no-return-assign": 0, // can make sense.
"no-shadow-restricted-names": 1,
"no-shadow": 0, // this is javascript. it has forEach and all that stuff.
"no-undef-init": 1,
"no-undef": 2,
"no-undefined": 0, // produces shorter code when testing against this
"no-use-before-define": 0, // can actually be used for a better overview, i.e. with module.exports
"no-unused-vars": 1, // a warning is sufficient

// Variables
"init-declarations": 0, // because no-undef-init is on and we actually want undefineds
"no-catch-shadow": 0, // no IE8 support anyway
"no-label-var": 1,
"no-restricted-globals": 1,
"no-return-assign": 0, // can make sense.
"no-shadow-restricted-names": 1,
"no-shadow": 0, // this is javascript. it has forEach and all that stuff.
"no-undef-init": 1,
"no-undef": 2,
"no-undefined": 0, // produces shorter code when testing against this
"no-use-before-define": 0, // can actually be used for a better overview, i.e. with module.exports
"no-unused-vars": 1, // a warning is sufficient
// Node.js and CommonJS
"callback-return": 1,
"global-require": 0, // only way to resolve cyclic references
"handle-callback-err": 1,
"no-mixed-requires": 1,
"no-new-require": 1,
"no-path-concat": 1,
"no-process-env": 1,
"no-process-exit": 1,
"no-restricted-modules": 1,
"no-sync": 0, // for loadSync

// Node.js and CommonJS
"callback-return": 1,
"global-require": 0, // only way to resolve cyclic references
"handle-callback-err": 1,
"no-mixed-requires": 1,
"no-new-require": 1,
"no-path-concat": 1,
"no-process-env": 1,
"no-process-exit": 1,
"no-restricted-modules": 1,
"no-sync": 0, // for loadSync
// Stylistic Issues
"semi": 1, // maybe next time
"no-extra-semi": 1,
"quotes": 1, // useful for gzip
"no-trailing-spaces": 1,
"no-unneeded-ternary": 1,
"unicode-bom": [2, "never"]

// Stylistic Issues
"semi": 1, // maybe next time
"no-extra-semi": 1,
"quotes": 1, // useful for gzip
"no-trailing-spaces": 1,
"no-unneeded-ternary": 1,
"unicode-bom": [2, "never"]

// ECMAScript 6 // maybe next time
}
// ECMAScript 6 // maybe next time
}
}
Loading

0 comments on commit 7aa864d

Please sign in to comment.