Git Product home page Git Product logo

vscode-javascript-repl-docs's Introduction

JavaScript REPL

JavaScript REPL is a javascript playground for Visual Studio Code with live feedback(logs or errors) as you type, besides your code, in a log explorer, or in an output channel. It supports Javascript, TypeScript, CoffeeScript and it can be used for development in Node.js projects or with front-end frameworks like React, Vue, Angular, Svelte etc.

vscode javascript repl in action

New Features

  • Markdown support on code blocks. Learn more
  • Playground for MDN Web docs, TypeScript official documentation, CoffeeScript, Node.js, lodash, RxJS and Ramda library. Learn more
  • Performance measurement. Learn more

Features

By pressing cmd(or ctrl) + shift + l as shortcut or by using the command "JS Repl: Run" and by using console.log statement,you can display the result of whatever expression you want (Variable, Function, Object etc..). JS Repl can be activated on file types(.js, .ts, .coffee, .jsx, .tsx, .vue) or by launching "JS Repl: New ...". Users can check the available commands or the extension's configuration on the wiki pages.

  • JavaScript, TypeScript and CoffeeScript support
  • Node.js support
  • React.js & Vue.js compatible
  • Logs through comments or by using console.log
  • Show or copy value of an expression, without add comments or console.logs
  • Explorer window with the log values and errors
  • Output window with the log values and errors
  • Live code coverage
  • Show log values on edit or or on save.
  • Imported files support
  • Easy install for missing modules
  • Multi-file support for logs or errors per project
  • Async results(logs, errors) rendering
  • ui customization in coverage & log colors

Preview video

Watch the video

Logging

Users can add logs in their code with the following ways:

// You can add logs by using console.log
console.log('We β™‘ JavaScript!');

// or by using a comment line with equals sign at the end of an expression
const obj = {
  language: 'javascript'
}; //=

function hello() {
  return 'Hello World!';
}
// or a comment block with equals sign
hello(); /*= */

// or just type the variable name
obj;

// if the log represents an object you can use the dollar sign to access its properties
obj; //= $.language

//  also inside the log comments you can print every expression in your scope
hello(); //= obj

// Besides, you can select one or more variables or expressions and press right-click
//and select show value or explore the logs at the explorer on the left

Installation

Users can find the extension in marketplace at the following url:

πŸŽ‰ https://marketplace.visualstudio.com/items?itemName=achil.vscode-javascript-repl

Javascript REPL requires node.js(>= 10.11.0) to be installed, and node executable to be available in PATH

Issues

Javascript REPL extension does not send any analytics data about the users or the kind of use that they are doing. So It will be very helpful, if you report an issue about a problem that you had during your repl sessions, and is really appreciated, if you provide any feedback about the extension user experience β™‘. More information about issues or the part of the source code that have not been open-sourced yet users can find on wiki pages.

Credits

The icons that I used are not mine, so I would like to say thank you to the following sources or persons:

The documentation resources in the playground markdown docs are served through the devdocs.io API.

This extension uses under the hood a modified version of Parcel bundler. So I would like to say a big thank you to the guys there. You can find the modified version at the following branch.

Inspiration

I'd like to give a shout out to Quokka.js, which is a significantly more comprehensive and covers a lot more editors, if this extension interests you - check out that too. Also, when I started to play around this, I started with the code of the following extension

vscode-javascript-repl-docs's People

Contributors

axilleasiv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vscode-javascript-repl-docs's Issues

Can't use npm installed modules.

vscode-remote > wsl2 alpine

start a project

$ npm init -f
$ npm install jsonpointer
$ code .

ctrl shift p > new repl

var jsonpointer = require('jsonpointer');

error: can't find module jsonpointer

❯ npx envinfo
npx: installed 1 in 4.324s

  System:
    OS: Linux 4.4 Alpine Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 6.19 GB / 31.86 GB
    Container: Yes
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 13.8.0 - ~/.nvm/versions/node/v13.8.0/bin/node
    Yarn: 1.22.4 - ~/.nvm/versions/node/v13.8.0/bin/yarn
    npm: 6.13.6 - ~/.nvm/versions/node/v13.8.0/bin/npm
  Managers:
    pip3: 19.2.3 - /usr/bin/pip3
  Utilities:
    CMake: 3.15.5 - /usr/bin/cmake
    Make: 4.2.1 - /usr/bin/make
    GCC: 9.2.0 - /usr/bin/gcc
    Git: 2.24.3 - /usr/bin/git
  IDEs:
    VSCode: 1.48.0 - /home/zenobius/.vscode-server/bin/db40434f562994116e5b21c24015a2e40b2504e6/bin/code
  Languages:
    Bash: 5.0.11 - /bin/bash
    Python: 2.7.18 - /usr/bin/python
    Python3: 3.8.2 - /usr/bin/python3
[Window Title]
Visual Studio Code

[Main Instruction]
Visual Studio Code

[Content]

Version: 1.48.0 (system setup)
Commit: db40434f562994116e5b21c24015a2e40b2504e6
Date: 2020-08-13T07:50:42.600Z (5 days ago)
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Windows_NT x64 10.0.20190

[OK] [Copy]

What do you think about releasing the code?

Hello! I was curious if you had plans to release the source code? The console.log via //= during eval is elegant. I have a tool I'm building that I'd like to incorporate that mechanic. No worries if not, life is full. Either way, thanks for the inspiration!

πŸ„

'JS Repl: Run' command does not work on js-files

Hello!

Looks like 'JS Repl: Run' command does not work on js-files. When I'm opening a js-file and run Cmd-Shit-P -> 'JS Repl: Run' command, I'm receiving an error 'The "from" argument must be of type string. Received type undefined'.

Image on 2019-11-13 03 11 25 PM

The same happens when you issue this command on newly created (not saved) file, which Language Mode is set to JavaScript.

The command 'JS Repl: New JavaScript file (js) is working fine.

Description: Interactive Javascript Playground
Version: 0.6.1
VSCode: Version: 1.40.0
macOS Catalina

Is Babel supported?

Hi,

I have some files that use experimental syntax- eg. nullishCoalescingOperator.
For some reason even with babel, the REPL shows SyntaxError on the lines that use experimental syntax :/

How to get the directory where the script is located?

When I do some file IO I need to read files from the same directory the file is located in, but I'm not sure how I can change the work directory to something that is relative to the script.

I'm working on Windows, and what I get back is:

image

Would be nice if the __dirname contains the \ or / characters. Might it be a bug?

Awesome extension BTW! Keep up the good work πŸ₯‡

ui-editor: no dom available

When the dom plugin is enabled in react apps, the history runs before it, so it recognizes that no dom is available. At the moment user needs to delete the line and recover back, in order for the repl to run again

const history = createHashHistory();
export const history = createBrowserHistory();

RangeError: Maximum call stack size exceeded

I don't know this is a bug or not.
but I just write this code then run JavaScript REPL.

const profile = {
  firstName: "John",
  lastName: "Doe",
  age: 18
};

const { firstName, lastName, age } = profile;

console.log(firstName, lastName, age);

I got a log message RangeError: Maximum call stack size exceeded

image

Add notification that node.js needs to be installed

Now, when users have not installed node.js in their system, repl is not running, without any notification to be shown to users that they need to have node.js installed and node.js version >= 10.15.0. Also, keep the node version in the log's file.

React Project Malfunctioning

What I'm experiencing is that when I start JS Repl in my index file (where is my ReactDOM.render) of the src folder, JS Repl works slow and is very buggy.

I have disabled all my other extensions

OS windows 10
VS Code v.1.60

Animation

Doesn't work on vue 3

I'm getting the error:
Error: Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead.

which is an error from vuejs and not from vue 3 as it already supports this situation

Typescript EROFS read-only error

Hi, I dont seem to be able to get the REPL working with typescript, is there something I am doing wrong? I am I required to configure anything? I even used the JS REPL new typescript command to create a file in my root
Thank you in advance

Screenshot 2020-11-15 at 19 21 30

Strict mode "use strict"

I'm trying to run the REPL with strict mode "use strict" which seems to break the inline evaluation.

How to reproduce

  • create a javascript file
  • run "JS Repl: Run" from the command menu
  • add "use strict" on first line

What is expected to happen

  • the REPL is evaluating as per documentation

What is actually happening

  • the REPL throws an error Illegal 'use strict' directive in function with non-simple parameter list

I'm unsure if this is a bug or if it is a lacking feature.. anyways, it would be quite useful to be able to run the REPL in strict mode. Let me know if I misunderstood anything.

Can't seem to make it work as NodeJS REPL inside Gatsby project

Hi, I'm new to the plugin and can't seem to make it work as NodeJS REPL.

I run the command JS REPL: New Javascript File (.js), it creates an Untitled-1.js (unsaved) file in my workspace and no matter what content I have inside the file it says there's an error with Babel in the first line...

I've tried including NODE_ENV=test in it but nothing I tried made it work.

Please refer to the screenshot for the context:
image

handler for infinite loops

When there is an infinite loop in users's code the REPL cannot provide any feedback logs. Add a warning message and a handler to stop the current repl session

The URL class anywhere in the input breaks execution

Example of breaking code:

const d = new Date() //=
const url = new URL('https://www.my.example.com:8080/app/name'); //=

If you remove the line with url, the d value will recalculate and show and update on every change.
If you restore the url line, updates stop. The url value is never shown neither in the //=, nor in the Logs Explorer.

Here the code uses WHATWG URL object, which is a recommended way.

The code will work if it uses a Legacy URL API (deprecated):

const url = require('url');
const app = url.parse('https://www.my.example.com:8080/app/name') //=

Insecure requests time out

Whenever I'm running any code that involves an insecure (http) request, it times out. I have no issues making https requests. I was thinking it must be some vscode/electron restriction, but the same code works with the Quokka.js extension, in the same version of vscode, for example.

Proxying objects?: REPL doesn't play nice with Immer

First: thank you for a brilliant extension. I use this all the time, and it makes my life much, much happier.

The issue is this: I've started using Immer to achieve immutability in a codebase. Immer checks that the objects it receives are "immerable," usually meaning that they are "plain" objects (i.e., object literals). The following work in VSCode running the REPL:

import produce from 'immer';

produce([1, 2, 3], draft => { draft.push(4); }); //=> [1, 2, 3, 4]

produce(Object.create(null), draft => { draft.foo = 42; }); //=> [Object: null prototype] { foo: 42 }

However, the following should work. And it does work just fine in Node, and in the command line Node REPL (14.6.0):

produce({}, draft => { draft.foo = 42; }); //=> { foo: 42 }

Using the JavaScript REPL, however, I get the following error when I run that code:

[Immer] produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '[object Object]'

Of course, I just passed in an empty object literal, a plain object.

I suspect the REPL is modifying the object literal in a way that is triggering this error because it fails some test in Immer. (Immer's source is not very easily navigable; I can dig into the code if you'd like.) Of course, ({}).constructor === Object.

Is the REPL proxying object literals? (But not objects with null prototypes?) Is there something else going on?

And againβ€”thanks for a really, really useful plugin. I've been using it intensively for months and am really delighted by it.

Error when using imported function, but works well if the imported function actually copied into the source code

Edit: seems to not be related to this extension exclusively. I'm also seen this behavior in "Node.js Notebooks". You may close it if it actually not related.

Hi,
I've been encountering an issue while using the extension.

This code generates error:

import { regexp } from 'parsimmon';
// not working: Error: not a regexp: /s/
regexp(/s/);

while this code, which is essentially the same, works as expected:

// copied from 'parsimmon'
function assertRegexp(x) {
  if (!(x instanceof RegExp)) {
    throw new Error("not a regexp: " + x);
  }
  // more code was here
}

function regexCopied(re, group) {
  assertRegexp(re);
  // more code was here
}

// works well
regexCopied(/s/, undefined);

Thanks

Context menu

Hi there, first of all thanks for the extension, it's quite helpful.

Is it possible to update it so that it's not sitting on top of the context menu or perhaps add a config setting so that the context menu can be turned on and off? It's currently breaking years of muscle memory.

Promises is always pending. Can't see value.

Not sure if I missed something obvious, but I'd expect to get back a value for this promise. Maybe, I'm just not understanding something πŸ˜…

Screen Shot 2021-10-05 at 11 19 57 PM

this is what the logs are showing as well. They seem to be cut off.

{"logs": [{"platform": "darwin"},{"jsdom":{"installed":false,"enabled":false},"asyncEnd":{"installed":false}},

[BUG] - Bcrypt not running properly

[PROBLEM]

Running javascript repl doesn't identify bcrypt functions properly

[HOW TO REPRODUCE]

import * as bcrypt from 'bcrypt';


class Teste {
    async main() {
        
        const passwords = [ 
            'anicepassword',
            'anicepassword2'
        ]

        for(const password of passwords) {
            const salt = await bcrypt.genSalt(12);
            let hash = await bcrypt.hash(password, salt);
            console.log(`password = ${password} - hash=${hash}`);
            console.log(await bcrypt.compare(password, hash))
            
        }
        
        
    }
}

new Teste().main();

[image result]

image

npx ts-node test.bcrypt.ts
image

Someone is facing the same issues or something like that?

FR: Wrap JS-Repl live feedback if Word Wrap is enabled. Possible?

Maybe it is a good idea to wrap JS-Repl feedback if Word Wrap is currently enabled?

Image on 2019-11-14 04 42 28 PM

Another one consideration: currently the JS-Repl feedback is cropped around 90th character. Can this be configurable? At least some sign, that the feedback is cropped should be added at the line end. Three dots, maybe (...)?

Stopped working since December

Has anyone else found that this fails to work at least since December or is it just me?

Tried clean reinstall

I've tried removing and reinstalling this extension and removing and reinstalling VSCode with myself logged out and the settings sync disabled. Even then, reinstalling this extension still results in the program failing.

Errors

Running JS Repl: Run

If I try to run the repl in the open file, I get this:

There is an unexpected error, would you like to submit this as issue on github? If so, please copy the contents of log file, and create an issue on github.

But the log file doesn't exist, and where the log file is meant to be had other log files present (before the reinstalling), but only with the latest log file being from December.

Running JS Repl: New Javascript File (.js)

Here are some errors I get when I try to open a new file JS Repl:


2023-01-16 04:41:42.095 [error] TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Style.hasDecorations (c:\Users\USER\.vscode\extensions\achil.vscode-javascript-repl-0.7.3\dist\main\extension.js:1:89262)
at c:\Users\USER\.vscode\extensions\achil.vscode-javascript-repl-0.7.3\dist\main\extension.js:1:327373
at Array.forEach (<anonymous>)
at c:\Users\USER\.vscode\extensions\achil.vscode-javascript-repl-0.7.3\dist\main\extension.js:1:327240
at d.invoke ([[PATH]]/extensionHostProcess.js:63:145)
at w.deliver ([[PATH]]/extensionHostProcess.js:63:2029)
at g.fire ([[PATH]]/extensionHostProcess.js:63:1667)
at [[PATH]]/extensionHostProcess.js:96:150378
at d.invoke ([[PATH]]/extensionHostProcess.js:63:145)
at w.deliver ([[PATH]]/extensionHostProcess.js:63:2029)
at g.fire ([[PATH]]/extensionHostProcess.js:63:1667)
at w.acceptDocumentsAndEditorsDelta ([[PATH]]/extensionHostProcess.js:96:13786)
at w.$acceptDocumentsAndEditorsDelta ([[PATH]]/extensionHostProcess.js:96:12176)
at u.N ([[PATH]]/extensionHostProcess.js:104:11208)
at u.M ([[PATH]]/extensionHostProcess.js:104:10926)
at u.H ([[PATH]]/extensionHostProcess.js:104:10019)
at u.G ([[PATH]]/extensionHostProcess.js:104:9000)
at [[PATH]]/extensionHostProcess.js:104:7788
at d.invoke ([[PATH]]/extensionHostProcess.js:63:145)
at w.deliver ([[PATH]]/extensionHostProcess.js:63:2029)
at g.fire ([[PATH]]/extensionHostProcess.js:63:1667)
at h.fire ([[PATH]]/extensionHostProcess.js:72:14314)
at [[PATH]]/extensionHostProcess.js:120:15804
at d.invoke ([[PATH]]/extensionHostProcess.js:63:145)
at w.deliver ([[PATH]]/extensionHostProcess.js:63:2029)
at g.fire ([[PATH]]/extensionHostProcess.js:63:1667)
at h.fire ([[PATH]]/extensionHostProcess.js:72:14314)
at c.y ([[PATH]]/extensionHostProcess.js:72:17324)
at [[PATH]]/extensionHostProcess.js:72:15795
at d.invoke ([[PATH]]/extensionHostProcess.js:63:145)
at w.deliver ([[PATH]]/extensionHostProcess.js:63:2029)
at g.fire ([[PATH]]/extensionHostProcess.js:63:1667)
at g.acceptChunk ([[PATH]]/extensionHostProcess.js:72:12045)
at [[PATH]]/extensionHostProcess.js:72:11332
at Socket.l ([[PATH]]/extensionHostProcess.js:72:19792)
at Socket.emit (node:events:526:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Readable.push (node:internal/streams/readable:228:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

2023-01-16 04:41:42.097 [error] TypeError: Cannot read properties of undefined (reading 'id')
at Style.clear (c:\Users\USER\.vscode\extensions\achil.vscode-javascript-repl-0.7.3\dist\main\extension.js:1:91712)
at Repl.setEditor (c:\Users\USER\.vscode\extensions\achil.vscode-javascript-repl-0.7.3\dist\main\extension.js:1:2715)
at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Repl.run (c:\Users\USER\.vscode\extensions\achil.vscode-javascript-repl-0.7.3\dist\main\extension.js:1:3624)
at async c:\Users\USER\.vscode\extensions\achil.vscode-javascript-repl-0.7.3\dist\main\extension.js:1:310545
at async s.h ([[PATH]]/extensionHostProcess.js:94:107614) achil.repl.runCurrent {"value":"achil.vscode-javascript-repl","c":"achil.vscode-javascript-repl"}

c:\Users\USER\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\
is replaced with [[PATH]] to keep the code block narrow.

unexpected error

There is an unexpected error, would you like to submit this as issue on github? If so, please copy the contents of log file, and create an issue on github

Doesn't work with typescript

Wanted a typescript sandbox in vscode. Always errors no matter what I do.

Steps to reproduce:

  1. JS REPL: New Typescript File (.ts)

  2. JS REPL: Run
    Result: Error "Illegal 'use strict' directive in function with non-simple parameter list"

extension not working at all (critical error)

When I try to launch js repl, it instantly crashes with no error message (log file is not created).

Steps to reproduce:

  • Attempt to run js repl.

Screenshots:

image

image

Attempted workarounds:

  • reloading
  • restarting vs code
  • restarting pc
  • reinstalling extension

(Resolved) Not working in create-react-app project

react repl

As per the description of this extension that says it can be used for development in Node.js projects or with front-end frameworks like React, Vue, Angular, Svelte etc.
As you can see i have written a console.log('hello') code inside Grid() function but it doesnt show the value. I tried changing few settings but no results. Can you help me in this. Thanks!

Impossible to run JSRepl on newly created (not saved) file

It is impossible to run JSRepl on newly created (not saved) file. If you run JS Repl: Run command on a new (not yet saved) file which Language Mode is set to, say, JavaScript - you will receive an error: "Use an approriate file to start repl: .js .jsx .vue .ts .tsx .coffee".

Image on 2019-11-14 11 50 21 PM

I'm pretty sure JSRepl should be able to run on a file with set Language Mode without saving it first (and it actually can do this, by creating a new file directly by JSRepl: by using command 'JS Rdpl: New ... file').

Stopped working after VS code and iOS latest updates

Hi Team,

Thank you for this extension, very useful.

Stopped working after VS code and iOS latest updates. No results for console.log('hello')

JS Repl:Run does nothing and hitting it the second time gives a warning: There is already a repl instance associated with this file

JS Repl: Stop for all files gives an error: Command 'JS Repl: Stop for all files' resulted in an error (IPC channel is already disconnected)

Please help

Thx
Rahul

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.