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

Cherry-pick ES6 targeting and big-integer addition to master #2208

Merged
merged 2 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libraries/adaptive-expressions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@types/xmldom": "^0.1.29",
"antlr4ts": "0.5.0-alpha.1",
"atob": "^2.1.2",
"big-integer": "^1.6.48",
"jspath": "^0.4.0",
"lodash": "^4.17.15",
"lru-cache": "^5.1.1",
Expand Down
20 changes: 12 additions & 8 deletions libraries/adaptive-expressions/src/expressionFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {convertCSharpDateTimeToMomentJS} from './datetimeFormatConverter';
import {MemoryInterface, SimpleObjectMemory, StackedMemory} from './memory';
import {Options} from './options';
import atob = require('atob');
import bigInt = require('big-integer')

/**
* Verify the result of an expression is of the appropriate type and return a string if not.
Expand Down Expand Up @@ -52,12 +53,12 @@ export class ExpressionFunctions {
/**
* constant of converting unix timestamp to ticks
*/
public static readonly UnixMilliSecondToTicksConstant: bigint = 621355968000000000n;
public static readonly UnixMilliSecondToTicksConstant: bigInt.BigInteger = bigInt('621355968000000000');

/**
* Constant to convert between ticks and ms.
*/
public static readonly MillisecondToTick: bigint = 10000n;
public static readonly MillisecondToTickConstant: bigInt.BigInteger = bigInt('10000');

/**
* Read only Dictionary of built in functions.
Expand Down Expand Up @@ -1693,12 +1694,12 @@ export class ExpressionFunctions {

private static ticks(timeStamp: string): {value: any; error: string} {
let parsed: any;
let result: BigInt;
let result: any;
let error: string;
({value: parsed, error} = ExpressionFunctions.parseTimestamp(timeStamp));
if (!error) {
const unixMilliSec: number = parseInt(parsed.format('x'), 10);
result = this.UnixMilliSecondToTicksConstant + BigInt(unixMilliSec) * this.MillisecondToTick;
result = this.UnixMilliSecondToTicksConstant.add(bigInt(unixMilliSec).times(this.MillisecondToTickConstant));
}

return {value: result, error};
Expand Down Expand Up @@ -2508,13 +2509,16 @@ export class ExpressionFunctions {
let error: string;
let arg: any = args[0];
if (typeof arg === 'number') {
arg = BigInt(arg)
arg = bigInt(arg);
}
if (typeof arg === 'string') {
arg = bigInt(arg);
}
if (typeof arg !== 'bigint') {
error = `formatTicks first argument ${arg} is not a number`;
if (!bigInt.isInstance(arg)) {
error = `formatTicks first argument ${arg} is not a number, numeric string or bigInt`;
} else {
// Convert to ms
arg = Number((arg - this.UnixMilliSecondToTicksConstant) / this.MillisecondToTick);
arg = ((arg.subtract(this.UnixMilliSecondToTicksConstant)).divide(this.MillisecondToTickConstant)).toJSNumber();
}

let value: any;
Expand Down
8 changes: 5 additions & 3 deletions libraries/adaptive-expressions/tests/expressionParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {Expression, SimpleObjectMemory, ExpressionFunctions, Options} = require('
var {TimexProperty} = require('@microsoft/recognizers-text-data-types-timex-expression');
const assert = require('assert');
const moment = require('moment');
const bigInt = require('big-integer')

const one = ['one'];
const oneTwo = ['one', 'two'];
Expand Down Expand Up @@ -506,7 +507,7 @@ const dataSource = [
['startOfDay(\'2018-03-15T13:30:30.000Z\')', '2018-03-15T00:00:00.000+00:00'],
['startOfHour(\'2018-03-15T13:30:30.000Z\')', '2018-03-15T13:00:00.000+00:00'],
['startOfMonth(\'2018-03-15T13:30:30.000Z\')', '2018-03-01T00:00:00.000+00:00'],
['ticks(\'2018-01-01T08:00:00.000Z\')', 636503904000000000],
['ticks(\'2018-01-01T08:00:00.000Z\')', bigInt('636503904000000000')],

//URI parsing functions tests
['uriHost(\'https://www.localhost.com:8080\')', 'www.localhost.com'],
Expand Down Expand Up @@ -728,7 +729,7 @@ const scope = {
timestampObj: new Date('2018-03-15T13:00:00.000Z'),
unixTimestamp: 1521118800,
unixTimestampFraction: 1521118800.5,
ticks: BigInt(637243624200000000),
ticks: bigInt('637243624200000000'),
user:
{
income: 110.0,
Expand Down Expand Up @@ -914,8 +915,9 @@ var assertObjectEquals = (actual, expected) => {
for (let i = 0; i < actual.length; i++) {
assertObjectEquals(actual[i], expected[i], `actual is: ${actual[i]}, expected is ${expected[i]}`);
}
} else if (bigInt.isInstance(actual) && bigInt.isInstance(expected)) {
assert(actual.equals(expected), `actual is: ${actual}, expected is ${expected}`);
}

else {
assert.equal(actual, expected, `actual is: ${actual}, expected is ${expected}`);
}
Expand Down
3 changes: 2 additions & 1 deletion libraries/adaptive-expressions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"compilerOptions": {
"target": "ESNext",
"target": "es6",
"lib": ["es2015", "dom"],
"module": "commonjs",
"declaration": true,
"declarationMap": true,
"downlevelIteration": true,
"sourceMap": true,
"esModuleInterop": true,
"outDir": "./lib",
Expand Down
3 changes: 2 additions & 1 deletion libraries/botbuilder-dialogs-adaptive-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "ESNext",
"target": "es6",
"lib": ["es2015", "dom"],
"module": "commonjs",
"declaration": true,
"sourceMap": true,
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-dialogs-adaptive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"ts-node": "^4.1.0"
},
"scripts": {
"test": "tsc && tsc tests/*.ts && nyc mocha tests/",
"test": "tsc && tsc ./tests/expressionProperty.test.ts && nyc mocha tests/",
"build": "tsc",
"build-docs": "typedoc --theme markdown --entryPoint botbuilder-dialogs-adaptive --excludePrivate --includeDeclarations --ignoreCompilerErrors --module amd --out ..\\..\\doc\\botbuilder-dialogs .\\lib\\index.d.ts --hideGenerator --name \"Bot Builder SDK - Dialogs\" --readme none",
"clean": "erase /q /s .\\lib",
Expand Down
6 changes: 3 additions & 3 deletions libraries/botbuilder-dialogs-adaptive/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"compilerOptions": {
"target": "ESNext",
"target": "es6",
"lib": ["es2015", "dom"],
"module": "commonjs",
"declaration": true,
"sourceMap": true,
"outDir": "./lib",
"rootDir": "./src",
"types" : ["node"],
"lib": ["es2020.string"]
"types" : ["node"]
},
"include": [
"src/**/*"
Expand Down
3 changes: 2 additions & 1 deletion libraries/botbuilder-dialogs-declarative/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "ESNext",
"target": "es6",
"lib": ["es2015", "dom"],
"module": "commonjs",
"declaration": true,
"sourceMap": true,
Expand Down