vscode-nodejs-repl icon indicating copy to clipboard operation
vscode-nodejs-repl copied to clipboard

Refactor code.

Open plylrnsdy opened this issue 7 years ago • 3 comments

  • Fix cannot import Node.js native modules, like require('util');
  • Refactor all code.
  • Use child process of User's Node.js as REPL.
    • Fix cannot use api of User's Node.js.
    • Fix cannot reload user module after changed the module's source.
  • Show error stack in hover message with plain text style;
  • Fix cannot import module using import {a as b} from 'c';
  • Fix results different with REPL outputs. #17
  • Add mulitple language support;
    • Add chinese translation.

plylrnsdy avatar Nov 26 '18 06:11 plylrnsdy

I'll take a look, but one thing first, I don't like Upper Camelcase or casing of filenames. It's confusing and easy to make mistakes when importing.

lostfields avatar Dec 04 '18 06:12 lostfields

This is my fault. I should not use git push -f. :sweat:

plylrnsdy avatar Dec 05 '18 12:12 plylrnsdy

There is a test file to look result of REPL:

// ========== Base Infomations ==========

// Current Node.js version
process.version;

// Current Work Dictionary
process.cwd();


// ========== Modules Import ==========

// ----- CommonJS -----
const assert = require('assert'); // Native Module
const util = require('util');

assert.equal(123, 123);
util.inspect({ abc: 123 });

// ----- ES6 import statements -----
// import * as xxx from 'xxx'; // Third-Partry Module
// import yyy from './yyy'; // User Module
import { inspect as Inspect } from 'util'; // Destruct Module

Inspect({ abc: 123 });


// ========== Value of Expression ==========

// ----- Value -----
undefined;
null;
true;
123;
'string';

// ----- Object -----
let arr = [1, 2, 3, 4, 5]; arr;
// Chain Call
arr.map(v => Math.sin(v))
    .filter(v => v >= 0);

let obj = {
    a: [1, 2, 3, 4, 5, 6],
    f: x => x,
    n: 123,
    o: {
        b: true,
        o: {
            symbol: Symbol('s'),
            c: class C { },
            e: new Date(),
        },
        s: 'string',
    },
}; obj;

/regexp/g;

new Date();

Symbol('A symbol');


// ========== Console ==========

console.log(arr);
console.debug(obj);
console.info('This is an array: %o', arr);
console.warn('This is a Warning.');
console.error('This is an Error.');

// ----- Console in loop -----
for (let i = 0; i < 10; i++)
    console.log(i);

// ----- Console in Function -----
function times(a, b) {
    console.log(`(${a}, ${b})`);
    return a * b;
}
for (let i = 1; i < arr.length; i++) {
    times(arr[i - 1], arr[i]);
}

// ----- Console in Promise -----
new Promise(resolve => setTimeout(() => resolve('This is result of Promise.'), 1000))
    .then(data => console.log(data));


// ========== Error ==========

throw new Error('message');

// ReferenceError
variable;

// TypeError [ERR_INVALID_ARG_TYPE]
let child = child_process.spawn('node', 'a.js');

// User Error
class MyError extends Error {
    constructor(message) {
        super(message);
    }
    toString() {
        return this.constructor.name + (this.message && `: ${this.message}`);
    }
}
throw new MyError('message');

plylrnsdy avatar Dec 06 '18 10:12 plylrnsdy